2013-04-12 51 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數據。 –

相關問題