现在,在FirstviewController中,我有一个按钮,当我点击它时,我使用委托获取值。现在,我想将此值发送到SecondViewcontroller并重新加载它的tableview数据。怎么做?如何使用nsnotificationcenter,但我尝试过,它不起作用。我将通知发布在Firstviewcontroller中实现的委托中。像这样的代码:
FirstviewController.m
// delegate that get selected cat
- (void)didSelectSubCat:(SubCat *)cat;
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"DidSelectCat" object:self userInfo:@{@"catId": cat.catId}];
}
SecondViewcontroller.m
- (void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectedCat:) name:@"DidSelectCat" object:nil];
}
- (void)selectedCat:(NSNotification *)notif
{
NSLog(@"userinfo: %@", [notif userInfo]);
}
答案 0 :(得分:0)
在SecondViewCOntroller中创建带有方法的协议
@protocol TeamListViewControllerDelegate <NSObject>
-(void)SecondViewController:(SecondViewController*)teamListViewController data:(NSString*)data
@end
宣布委托
@property(nonatomic,assign) id<TeamListViewControllerDelegate> delegate;
在firstViewcontroller中遵循该协议并实现该方法并在该方法内部刷新表。 我希望这会有所帮助。