【问题标题】:How to reload another view controller's tableview data如何重新加载另一个视图控制器的 tableview 数据
【发布时间】: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


【解决方案1】:

在 SecondViewCOntroller 中使用方法创建协议

     @protocol TeamListViewControllerDelegate <NSObject>

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

        @end

声明委托

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

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

【讨论】:

  • 但我没有从 SecondViewController 获取数据。我要把数据发送到SecondViewController,并刷新SecondViewController的tableview数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 1970-01-01
  • 1970-01-01
  • 2015-09-10
  • 2019-09-09
  • 2014-11-13
  • 1970-01-01
相关资源
最近更新 更多