2013-04-12 56 views
0

现在,在FirstviewController中,我得到一个按钮,当我点击它时,我使用委托返回值。现在,我想将此值发送到SecondViewcontroller并重新加载它的tableview数据。怎么做?如何使用nsnotificationcenter,但我已经尝试过,它不工作。我将通知发布到Firstviewcontroller中实现的委托中。这样的代码:如何重新加载另一个视图控制器的tableview数据

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遵循的协议和实现该方法和该方法刷新表里面。 我希望这会有所帮助。

+0

但我没有从SecondViewController获取数据。我要将数据发送到SecondViewController,并刷新SecondViewController的tableview数据。 –

相关问题