the first screen shows a list of categories in tableview
select one item goes to the next screen which shows a list of items in that category in a tableview and shows a home nav button back.
and selecting an item in this view would take me to a detail view showing a nav button back to that category i just selected.
all the examples i've found are 1 level only.
does anyone know of any examples or this how to program this?
The back button means 1 back, and that's it. But if you want to go two back when you tap something or press a button or something, you can always put in some code like this and it'll go two back, nicely animated
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[viewControllers removeLastObject];
[viewControllers removeLastObject];
[self.navigationController setViewControllers:viewControllers animated:YES];
Related
I have a TabBarController that is linked to 4 ViewControllers, so the tab bar displays 4 items, but I only want to display 3 items.
How to I hide the other tab bar item?
I want that the ViewController that is no displayed on the tab bar also displays the tab bar.
Here is the story board:
And here is the app on the simulator:
I want the "Notificaciones" item to be hidden (it is the initial view that is displayed)
Thanks!
You can remove the UITabBarItem with the following code:
NSMutableArray *tabBarViewControllers = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[tabBarViewControllers removeObjectAtIndex:0];
[self.tabBarController setViewControllers: tabBarViewControllers animated:YES];
It looks like the way you have this setup right now, that once you select one of the other views, you will not be able to return to the Notificaciones view without reloading the whole UITabBarViewController.
I want to implement a "Next" feature in my app. The button appears on a ViewController that is shown by clicking on a row in a UITableView. Ideally what I would like is for Next to do the following (in pseudo code)
Go "back" to the UITableView
Scroll to next available item in UITableView
Select that item
I believe I can do 2,3 via selectRowAtIndexPath (please feel free to correct me if I am wrong) but I am unsure how to do Step 1. I will also have to target a method in the UITableView rather than the UIViewController that hosts the Button. How would I achieve this?
Update:
I can now target the rootViewController but now do I actually show it? (For reference here is my code, thanks to this question)
NSArray *viewControllers = self.navigationController.viewControllers;
UIViewController *rootViewController = [viewControllers objectAtIndex:viewControllers.count - 2];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:#"Next" style:UIBarButtonItemStyleDone target:rootViewController action:#selector(nextButton:)];
Update 2
I now have the back animation working but it keeps the navigation bar intact, how do I also set this back to the correct (rootViewController) one?
[self.navigationController popToRootViewControllerAnimated:YES];
If you have situation like this:
RootViewController - tableView
NextviewController - some view with Next button which shows after the you click on tableView
When you issue [self.navigationController popToRootViewControllerAnimated:YES]; from the 2. controller by pressing the Next button, it will bring RootViewController to the screen.
Now, on the RootViewController you have to "detect" back action (perhaps in ViewWillAppear) and continue with your steps 2. and 3.
Everyone
I have a problem and I have been searching the solution but could not find any. I am working on a tab bar based app. Problem is that I want to hide tab bar at first screen and then show it on all other screens that are being displayed after first screen.
Can anyone please give me the best solution for this problem?
Actual scenario is that I have a screen that is login screen. Now i dont want to show tab bar here as tab bar will be displayed only if the user is signed in. When user logs in, I want the tab bar to be displayed showing its contents.
Best Regards
If you have your Tab Bar Controller as your rootController, you can use rootController.selectedIndex =0 for selecting 1st Tab bar Item, and rootController.selectedIndex =1; and so forth.
As soon as that particular view loads, you can load the other views in an array, and then add it to the rootController.selectedIndex and reloadInputViews with animation.
Edit: (as per the comments)
So you have a tab bar controller, and you want to show the introduction and the login screen while starting the App. If login is successful, you want to present the tab bar controller ! This can be done with ModalViewControllers
In the ViewDidLoad of the view that loads up first, (it's your first tab by default), add
//Declare Introduction Screen//
IntroductionController *introductionController = [[IntroductionController alloc] initWithNibName:#"IntroductionController" bundle:[NSBundle mainBundle]];
//Give a navigation screen for your introduction screen and set it to introduction screen
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:introductionController];
navController.title = #"Introduction";
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:NO];
Now your introduction screen would load as soon as your first tab bar loads. But the loading is instantaneous, so it's not visible to the user's eye. Now reference your Login View Controller like #class LoginController and create an object LoginViewController *lvc;, and synthesize it. Now declare LoginButton and in the IBAction
-(IBAction) loginAction: (id) sender{
NSLog(#"I clicked Login");
if (self.lvc ==nil){
self.lvc = [[LoginController alloc] init ];
}
lvc.title = #"Login";
[self.navigationController pushViewController: self.lvc animated:YES];
}
And in the LoginViewController, if Login is successful, just do
[self dismissModalViewControllerAnimated:YES];
create an outlet for the uitabbar, then declare it hidden in the first screen, then create a new void, NOT SENT SO IT DOESNT WORK in the first screen, make it say, lets say, hide. And inside hide, put code saying your uitabbar.hidden = YES; then, to make it work in the other view, write this in the viewDidLoad:
[(//first view*)[UIApplication sharedApplication].delegate //the void, in this case, hide];
I am making an application which has a main TableView in which every cell has details. when cell is clicked DetailView of that cell shows details. DetailView also has next and prev button from which we can go to next cell information without going back to main TableView. I want Back button in DetailView to work like that whenever i ll click it, application should show main TableView. Is there any way to do that?
I think i didnt explain my problem well. I have items in main TableView cells. and every cell creates a detail view when i click on that. there are next and previous buttons in every detailview so we can check next item details without going back to main table view. there is a back button on every detail view. for example if u clicked 3rd cell to see details. and then u went to 4th item's detail by using next button. now if u ll click back button it ll go back to 3rd view detail not the main table view. i wanna go back to main table view whenever i ll click back button. thats the problem.
s u can do this by
[self.navigationController popViewController:YES];
through this without using back button. when u click on cell detailview, it goes back to the view
Main view is called Root, use this
[self.navigationController popToRootViewControllerAnimated:YES];
Have you tried to push the detailview like this:
YourDetailView * detailView = [[YourDetailView alloc] init];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
I have two tabs in my app, each of them is a UITableView, and each of the views in the two tabs has its own DetailViewController.
Now, if I click on a TableViewCell in the DetailViewController in the first tab, I want to jump to the DetailViewController of the second tab. I know how to access the second tab
self.tabBarController.selectedIndex = 1;
and I know how to access the DetailViewController, but only without jumping to the second tab.
Is it possible to access the second tab, and then access its DetailViewController?
It would be best if the main TableView in the second tab wouldn't be visible at all, so, it should jump directly to the DetailViewController of the second tab, with the navigation controller showing the "back" button to the main view controller and the second tab highlighted. Is this possible? And, if it is, how can I do this?
Thanks in advance :-)
The tabBarController has an array with the viewController of every tab. You can push the DetailViewController like this:
[[self.tabBarController.viewControllers objectAtIndex:1] pushViewController:detailViewController animated:NO];
Before that you might want to pop to the rootViewController:
[[self.tabBarController.viewControllers objectAtIndex:1] popToRootViewControllerAnimated:NO];