3
votes

I have a UITableViewController, example NewsfeedController and have synthesis property for set / get.

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

It shows error: [UITabBarController setSelectedViewController:] only a view controller in the tab bar controller's list of view controllers can be selected.'

I see in UITabBarController setSelectedViewController: only a view controller in the tab bar controller's list of view controllers can be selected, it says "remove the synthesis of the array of view controllers you are passing".

Can u give the full code how to implement? What I need is, I want to change to other tab and pass variable, so in the NewsfeedController can use the variables. If I use [self.tabBarController setSelectedIndex:0] it can change the tab, but how do I pass the variable and trigger refresh / reinit the view?

And if possible, if use setSelectedViewController, can it change to view that is not listed in all tab controller items. (For example in UITab the tabs are: tab1, tab2, tab3. But I want to change to tab4).

1
WHY do you want to reinit any view? That is a very clear sign of not well written code - you should not have to reinit / reload a view.luk2302

1 Answers

5
votes

You need to get a reference to the NewsFeedController that is already in the tab bar controller, not create a new instance (which is what you're doing with the code you posted). You get that reference from the tab bar controller's viewControllers property. So, for instance, if the NewsFeedController is in the second tab (the one at index 1), you would do this,

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