2013-04-12 2 views
0

지금 바로 FirstviewController에서 버튼을 하나 클릭했습니다. 클릭 할 때 대리자를 사용하여 값을 다시 가져옵니다. 지금 당장이 값을 SecondViewController로 보내고 테이블 뷰 데이터를 다시로드하려고합니다. 그렇게하는 방법? 방법에 대한 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 

firstViewcontroller에서 해당 프로토콜에 따라 그 방법을 구현하는 방법 새로 고침 테이블 내부

 @property(nonatomic,assign) id<TeamListViewControllerDelegate> delegate; 

선언 위임 . 도움이되기를 바랍니다.

+0

하지만 SecondViewController에서 데이터를 가져 오지 못했습니다. SecondViewController에 데이터를 보내고 SecondViewController의 tableview 데이터를 새로 고칩니다. –

관련 문제