Reputation: 33
I have a UITableView and I want to switch to another tab upon clicking a cell in UITableView.
I have already tried that but it doesn't work
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
MainView *mainView = [[MainView alloc] initWithNibName:@"MainView" bundle:nil];
mainView.tabBarController.selectedIndex = 3;
}
Upvotes: 3
Views: 5092
Reputation: 385600
You're loading a new copy of your MainView each time a row is selected. These new copies aren't displayed anywhere. You need to access the tab bar controller of your existing, displayed instance of your main view. Perhaps this will work:
self.tabBarController.selectedIndex = 3;
Upvotes: 15