0

Right now, in FirstviewController, I got a button, when i clicked it, I get the value back using delegate. Right now, I want to send this value to SecondViewcontroller and reload it's tableview data. How to do that? How about use nsnotificationcenter, but i have tried, it's not working. I post the notification in the delegate that implemented in Firstviewcontroller. the code like this:

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]);
}
4

1 回答 1

0

在 SecondViewCOntroller 中使用方法创建协议

     @protocol TeamListViewControllerDelegate <NSObject>

       -(void)SecondViewController:(SecondViewController*)teamListViewController data:(NSString*)data

        @end

声明代表

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

在 firstViewcontroller 中遵循该协议并实现该方法并在该方法刷新表中。我希望这将有所帮助。

于 2013-04-12T11:00:03.933 回答