【发布时间】:2013-04-12 19:00:03
【问题描述】:
现在,在 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]);
}
【问题讨论】:
-
嘿使用协议概念.....
标签: iphone delegates notifications viewcontroller