i have a tabBarController with 3 items.
In my first view in my first item of my tabBar i have a tableview and a navigationController.
how to go in the second item of my tabBar when i push 1 row in my tableview in the fist item of my tabBar?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Second *two = [[Second alloc] initWithNibName:#"Second" bundle:nil];
[self.navigationController pushViewController:two animated:YES];
[two release];
thks
Use the selectedIndex property on the UITabBarController. More information can be found in the UITabBarController Class Reference.
self.tabBarController.selectedIndex = 1;
or use
[self.tabBarController setSelectedIndex:1];
Note that the indices start at 0, so the second tab is at index 1.
Its not a good practice to automatically select a tabBarItem when a view controller is pushed into a navigation controller stack of another tabBarItem. If you want the Second view to be in second tab, you should add that view controller to the second tab.
Related
I have an iOS 7 application that has a Tab Bar controller. On one tab I have a tableView, from which I can select a cell, and navigate to a detail view.
On the detail view I had the following to be able to navigate to another view:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Table View Cell Clicked on row: %ld", indexPath.row + 1);
ThirdViewController *view = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:[NSBundle mainBundle]];
modelView.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:view animated:YES];
}
But this does not let me navigate to the new View. How can I navigate to multiple view, I require this:
View1 -> View2 -> View3 -> View4 -> View5 -> View6 - All these view contain a table view, and the selection to another view is by selecting on row on the table.
Thanks
Best Regards
UPDATED:
Problem solved. the last table view did to add the delegate outlet set. That wa the problem. Thanks
Check if self.navigationController is nil. If it is, it means you need to add navigation controller to the tab view controller:
[tabViewControllers addObject:[[UINavigationController alloc] initWithRootViewController:myTableViewController]];
tabBarController.viewControllers = tabViewControllers;
I've got a uitabbarcontroller set as the root view of the window. One of the tabs in the tabbar is set to a subclass of uitableviewcontroller. What I'm trying to do is show a details view when one of the rows is touched so I implemented
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!detailViewController) {
detailViewController = [[ItemDetailViewController alloc] init];
}
[detailViewController setEditingArray:
[list objectAtIndex:[indexPath row]]];
[[self navigationController] pushViewController:detailViewController animated:YES];
}
in my table controller, but when I select the row, my detailview doesn't pop in. I added nslog to see if the function fires - and it does, but my detailview still doesn't show. Any ideas?
Thanks.
The tableViewController should be placed inside a NavigationController.
I guess you created tableView inside a tab bar.
TableViewControllerSubclass* table = [[TableViewControllerSubclass alloc] init];
UINavigationController* tableNav = [[UINavigationController alloc] initWithRootViewController:table];
mainController = [[UITabBarController alloc] init];
mainController.viewControllers = [NSArray arrayWithObjects:tableNav,..., nil];
You don't have a navigation controller ([self navigationController] is returning nil). Instead of having the table view controller as the root of the tab, make the tab's root a navigation controller containing the table view controller. You will now be able to push the detail controller from the table view controller.
I've got an app with a UITabBarController that controls several UIViewControllers. Within that controller there is a UITableViewController. I'm trying to figure out how I can select a row on my tableview and push the view controller of one of my other tabs while actually navigating to that tab.
I've used performSegueWithIdentifier: but it pushes the new view onto the same tab that my tableview is in. I'd like to navigate to the tab that the view I'm pushing to is on.
In case I haven't been clear: My tableview is in Tab 1. I click on a row. I want to get to Tab 2. So far I've been able to push the view controller for Tab 2 onto Tab 1. No Good.
Can anyone shed some light?
Thanks
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger theIndex;
[self.tabBarController setSelectedIndex:theIndex];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *tab2ViewController = [self.tabBarController.viewControllers objectAtIndex:1];
NewViewControllerToPush *mvc = [[NewViewControllerToPush alloc] init];
[tab2ViewController.navigationController pushViewController:mvc animated:YES];
[mvc release];
}
When you enter the viewControllers in your tabBar, make sure to wrap them inside a UINavigationControllers, otherwise you would not be able to use push and pop functionalities.
I have a Tab Bar application with 6 Tab Bar items that each open a UITableView. I am trying to enable each table with the ability to open a Detail View Controller when an item in a row on the table is selected.
For example, for the first ViewController ( ViewController1.m ), I created
DetailView1.xib
DetailViewController1.h
DetailViewController1.m
In order to get each row in ViewController1.m 's TableView, I understand I must
use this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
This is my code for that method, which does not produce any errors or warnings, but nothing sees to happen when the TableViewCell is selected:
DetailViewController1 *dvController = [[DetailViewController1 alloc] initWithNibName:#"DetailView1" bundle:[NSBundle mainBundle]];
[navController pushViewController:dvController animated:YES];
[dvController release];
Should this not load DetailView1.xib? I created this with the Tab Bar Application Template...which has no NavigationController in it by default I believe. Is it possible something is not hooked up right in Interface Builder?
You'd need to configure each tab to contain an instance of UINavigationController with one of your view controllers nested inside of it. Then in tableView:didSelectRowAtIndexPath:, you'd want to change the second line of code in your example to this:
[[self navigationController] pushViewController:dvController animated:YES];
I recently found a good tutorial about how to place a navigation controller within a tabbarcontroller("The nib way").
http://twilloapp.blogspot.com/2009/05/how-to-embed-navigation-controller.html
I continued with the second step and added a tableviewcontroller to the navcontroller.
What I don't understand, is how I can use the navigationbarcontroller from within my tableviewcontroller and e.g - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
What I want to do is when a user selects a row another view should slide in with the back button and everything that a navigationcontroller provides.
Thanks in advance!
Have you started with Apple's SimpleDrillDown sample? The specific code in question is this routine:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
Create the detail view controller and set its inspected item to the currently-selected item
*/
DetailViewController *detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
detailViewController.detailItem = [dataController objectInListAtIndex:indexPath.row];
// Push the detail view controller
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
}
The following was what I was looking for:
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
Since I've specified the RootView Controller for my NavigationControllers View, self answers to navigationController.