传值方
.h文件
#import <UIKit/UIKit.h>
@class AddPushCourseSearchModel;
//自定义类型
typedef void(^SelectedDiseaseBlock)(AddPushCourseSearchModel *searchModel);
@interface AddPushCourseSearchViewController : UIViewController
//声明自定义类型
@property (nonatomic, copy) SelectedDiseaseBlock selectedDiseaseBlock;
- (void)returnDisease:(SelectedDiseaseBlock)block;
@end
.m文件
- (void)returnDisease:(SelectedDiseaseBlock)block{
self.selectedDiseaseBlock = block;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//点击Cell 添加回调函数,传model
AddPushCourseSearchModel *model = _courseList[indexPath.row];
if (self.selectedDiseaseBlock) {
self.selectedDiseaseBlock(model);
[self backAction];
}
}
接收方
- (void)nurseAddIllnessEvent{
AddPushCourseSearchViewController *VC = [[AddPushCourseSearchViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];
[VC returnDisease:^(AddPushCourseSearchModel *searchModel) {
#warning 拿到model,刷新界面
}];
}
其实可以不在.h文件暴露方法
传值方
.h文件
#import <UIKit/UIKit.h>
@class AddPushCourseSearchModel;
//自定义类型
typedef void(^SelectedDiseaseBlock)(AddPushCourseSearchModel *searchModel);
@interface AddPushCourseSearchViewController : UIViewController
//声明自定义类型
@property (nonatomic, copy) SelectedDiseaseBlock selectedDiseaseBlock;
@end
.m文件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//点击Cell 添加回调函数,传model
AddPushCourseSearchModel *model = _courseList[indexPath.row];
if (self.selectedDiseaseBlock) {
self.selectedDiseaseBlock(model);
[self backAction];
}
}
接收方
- (void)nurseAddIllnessEvent{
AddPushCourseSearchViewController *VC = [[AddPushCourseSearchViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];
VC.selectedDiseaseBlock = ^(AddPushCourseSearchModel *searchModel) {
#warning 拿到model,刷新界面
};
}
小白总结,欢迎打脸指正