傳值方
.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 添加回調(diào)函數(shù),傳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 添加回調(diào)函數(shù)栖茉,傳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,刷新界面
};
}
小白總結(jié)玉组,歡迎打臉指正