When my app launches, it presents a navigation view with a tableview and a tabbar on the bottom.
Something like this:
TabBar --> UINav1, UINav2, UINav3, UINav4
Each UINav contains a ViewController that is eventually displayed.
What I want to be able to do is to change the UITabBar if the user moves from the ListView (Main screen) to the detail view.
I don't have to swap out the whole tabbar atleast change/remove the buttons.
However, if I use the above model (setting TabBarController as the root controller) then it seems it's pretty much stuck and immutable in the course of the navigation. The best I can do is just hide it in certain views.
Been banging my head for like a day trying to figure this out.
Thanks!
You could use
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
in your UITabBarController to set the tabBar whatever viewController you wish
EDIT: You might wan't to look at this question wish seems to be quite similar iPhone, how I hide a tab bar button?
It is not very common but you can present a new tab bar controller along with its associated view(s) modally.
Assuming your listView is a UITableViewController, you can push the new tab bar controller in your didSelectRowAtIndexpath method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
[self.tabBarController presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated]
PS: I would be very careful with how you structure your UI in this case as it can get quite confusing for the user).
I hope it helps.
Rog
Upon further research, decided that this was not feasible to do.
Related
I want to make a tableview; when you press a cell it takes you to another tableview. If you press a cell on the second table, it takes you to another view. Then, you could go back if you want or whatever. How would I do this? I can make a tableview lead to a new view already, but the real question is how to make another tableview and lead to another view.
I'm not sure if I follow..
Anyhow, I recommend you create a UINavigationController and set the rootViewController to your tableView's controller view property, when a cell is tapped in your tableview you should implement:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
where you would create an instance of another view controller that holds your desired "different" tableview obviously and push it to the navigation controller.
I recommend you take a look at the view controllers programming guide as well as tableviews. It isn't that complex.
The key idea is to know that this behavior you want is basically how the navigation controller works by pushing and popping views.
If you implement it this way (which is what you should be doing) you get lots of functionality for free, such as the behavior when tapping on the "back" button.
Hope it helps.
Do you want to use both tables in the same view controller or do you want to use navigation controller to navigate to the next table view? If you want to use both the tables in the same view controller then differentiate them by tag value.
Hi all,
this is a typical layout of one of apps. Now what I want on clicking of row of one of the view controllers(table view), I want to change the index of of the tab. Lets say I am in 3rd view, I want to move to the 1st view.
I tried with navigation controller's didShowViewController delegate method. Seems its not working. Could you please suggest any other way to do this?
Thanks.
Just use the below code in didSelectRowAtIndexPath method of UITableView, then you just need to set the SelectedIndex for Tabbar.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
[self.tabBarController setSelectedIndex:indexPath.row];
}
in my program I need a tableview and, when you click onto a row, the view scroll left and show the details (like the mail for example...)
how can I do this??
I explain... it's an automatic thing or I need to manage by hand the animation of the view??
thanks in advance
I use UINavigationControllers to achieve this effect of the detail animating left when you click on the row. So you need a UINavigation controller above the UIViewController or UITableView Controller that controls your table.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...my code
[self.navigationController pushViewController:myViewController animated:YES];
}
Your case is exactly what UINavigationController class is for - it will handle your controllers hierarchy and will do animated transition for you as well. To learn how to use it you can have a look at Apple's NavBar sample.
I have an app with a navigation controller that I would like to add a tab bar to. Does anybody know if its possible to say something like if the fist tab is selected show view1 if tab 2 is selected show view2? If theres code for that then I would be good to go. Any help is appreciated. Y+Thanks
According the interface guidelines, a tabbar should always be at the top level of the app. In other words, you should have a tabbar and then have a navigation controller inside each tab.
If you need to display views as with a tabbar but not at the top level of the app, use a segmented control. Users will understand they are choosing alternate views but they won't be confused about where in the app they are.
You shouldn't be using a UITabBarView without a UITabBarViewController.
Why do you not want to use a TabBarController?
Otherwise you can simply add a tabbar and implement the UITabBarDelegate protocol to react to changes. Which is essentially implementing your own TabBarController.
You will need to create a Tabbar and set the delegate to an object that implements the following method, where you can switch view based on the selected tabbarItem:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
int index = [tabBar.items indexOfObject:item];
switch (index) ...
}
I have a NavBar, a TabBar and a SearchBar with a ScopeBar. So the user can perform a search via a remote server. Clicking on one TableRow of the TableView a new ViewController with a xib is pushed into.
It is doing some calculations and it is possible, that I have to dismiss this View(Controller) and I should go back like I am clicking the "back" button in the NavBar.
How could I do this programmatically and call a method in this ViewController, because I have to trigger the search with the saved search term.
Does anyone know this?
Thanks a lot in advance & Best Regards.
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
if you are
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
Use delegation. Have the table view controller create your new view controller newViewController and set newViewController.delegate = self before pushing it onto the navigation stack.
Then in newViewController, just before you popViewControllerAnimated: call some method like [delegate doWhateverWhenNewViewControllerIsPopped: ...]. Ideally you declare a protocol called something like NewViewControllerDelegate and have the controller above implement it.
You can change the back button of NewViewController to something like "Done" or whatever by changing it's left navigation button. (See the properties of UIViewController.)
Hope that makes sense.
I solved the problem, take a look at the comments.