首页 文章

UITabBarController setSelectedViewController只有一个视图控制器在标签栏控制器的视图控制器列表中可以选择

提问于
浏览
2

我有一个UITableViewController,例如NewsfeedController,并具有set / get的综合属性 .

NewsfeedController* vc = [[NewsfeedController alloc] init];
vc.tagId = 10;
[self.tabBarController setSelectedViewController:vc];

它显示错误:[UITabBarController setSelectedViewController:]只能选中标签栏控制器的视图控制器列表中的视图控制器 .

我在UITabBarController setSelectedViewController: only a view controller in the tab bar controller's list of view controllers can be selected看到,它说"remove the synthesis of the array of view controllers you are passing" .

你能给出完整的代码如何实现?我需要的是,我想更改为其他选项卡并传递变量,因此在NewsfeedController中可以使用变量 . 如果我使用[self.tabBarController setSelectedIndex:0]它可以更改选项卡,但是如何传递变量并触发刷新/重新启动视图?

如果可能,如果使用setSelectedViewController,它是否可以更改为未在所有选项卡控制器项中列出的视图 . (例如在UITab中,选项卡是:tab1,tab2,tab3 . 但我想更改为tab4) .

1 回答

  • 4

    你需要获得对标签栏控制器中已经存在的_1755254的引用,而不是创建一个新实例(这就是你're doing with the code you posted). You get that reference from the tab bar controller' s viewControllers 属性 . 所以,例如,如果 NewsFeedController 在第二个标签中(在索引1),你会这样做,

    NewsfeedController* vc = self.tabBarController.viewControllers[1];
    

相关问题