I'm currently working on an iOS app in Xcode.
I have a few View Controllers that are part of a tab bar controller. I also have another view controller, that I access with a push from a button on one of the tabs (modal segue). I also have a back button on this extra view which is also a segue that leads back to the view controller where we came from.
However, when I press this back button, and come back on the view controller that was part of the tab controller, the tab bar at the bottom is no longer displayed.
Why is this happening and how can I solve this?
Try this, this will help you
- (void)viewWillDisappear:(BOOL)animated
{
self.hidesBottomBarWhenPushed = NO;
}
Try adding ViewController.hidesBottomBarWhenPushed = NO; when you are popping back to the viewcontroller.
Related
I don't want to let the navigation controller show its navigation bar in the whole project.
Now there are three view controllers
(1) Login view controller
(2) Sign up view controller
(3) Home view controller.
I just hope to use action(which can be triggered by any kind of event, i.e. drag gesture, not necessary the pressing button) to switch between these view controllers. But I found once I get to the "signup view controllers", I can not go back to the login view controller, since there is no "BACK" navigation bar.
Questions:
How "PUSH" in one view controller, then "POP" in the other view controller?
Or there is some different way to solve this problem?
Thank you so much, any suggestion is great.
To programmaticaly go backward in a navigation controller's navigation stack, call this method:
[self popViewControllerAnimated:YES];
When and where you call this is up to how you want your app to flow. Essentially, the default navigation controller calls this automatically when the navbar's back button is pressed. But if you hide the navbar and still need to pop back, you can call this method to pop back.
As for pushing forward, it's simply a matter of creating a Push segue on the storyboard, giving it a name, and then in your code, call this method:
[self performSegueWithIdentifier:#"segue_YOUR_SEGUE_ID" sender:self];
On the question of your app, what probably makes most sense is for the login view be a view by itself. It should contain a modal segue to a sign up view for new users as well as a modal segue to the home view controller (which may or may not need to be embedded in a navigation controller).
Performing a modal segue works exactly the same as a push segue (if you're using storyboards. Hook up the segue, choose a modal segue, then call the performSegueWithIdentifier: method in your code when you need the segue to occur.
Dismissing a modal view is slightly different, but still quite simple. It goes like this:
[self dismissViewControllerAnimated:YES completion:nil];
It's fairly check to do with an 'if' statement...
if (self.navigationController.navigationBarHidden == NO) {
//YOUR ACTION
}
Hope that helps!
I am looking for a way to dismiss a modal view and switch to a specific tab on the tab bar.
I think I need to combine....
self.tabBarController.selectedIndex = 3;
and
self.dismissModalViewControllerAnimated:YES;
Both work individually but not when combined.
How about setting the tab bar's selected index upon the calling of viewDidDisappear or viewWillDisappear for the dismissed controller? This way, they won't be called together but will happen one after the other
In my test project I have some 5 tabs on click of a tab it will go to that corresponding class, on click of back in that screen I will come back to my home page but with out the tab bar.. earlier what 5 tabs were there those are not coming ...
following code I am using under back button
where DataEntry is the class to where i need to navigate
- (void) back_Clicked:(id)sender
{
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithTabBar];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
[self. navigationController presentModalViewController:addNavigationController animated:YES];
}
is I have to add that navigation controller to the tab view? how can I get the tab bar on click of back can any one help me ,thanx in advance
As I understand this, you must already be pushing this view controller either via navigation controller or modally. So the idea would be to simply dismiss it right?
If you have used [self.navigationController pushViewController:animated:] then just do [self.navigationController popViewControllerAnimated:YES]; . This should take you back to the earlier view controller.
If you have presented this modally like you have done here, you should do [self.navigationController dismissModalViewControllerAnimated:YES];.
If you need to return back from a view to the previous view using a back button inside a tab view , i would recommend using a navigation controller inside the view for each tab where you require this functionality. Trying to implement a custom back button without using the navigation controller, in my opinion, is only making things tough for yourself.
If you only want one view to be displayed when you tap on a tab bar button then an ordinary view controller inside the tab bar view should suffice.
The tab bar shouldnt be disappearing altogether unless its been implemented incorrectly.
I'm writing an iPhone app that is based on a UINavigationController. I'm pulling data from a server that sometime returns bogus links. I open each link by pushing a webview viewcontroller. I want to be able to include some error handling. I know if the link is no good. So I want to be able to pop the webview view controller as soon as I know that my webview has encountered an error.
Currently, I've tried using the following code:
[self.navigationController popViewControllerAnimated:YES];
I then get a Navigation bar with nothing displayed in it, but if I click where the "back" button should be it operates appropriately. The title pops up when I click where the "back" button should be. The view where the viewcontrollers usually display there content is blank white too even though I'm popping back to a UITableViewController.
I've tried this as a workaround:
UINavigationController *nav = self.navigationController;
[self.navigationController popViewControllerAnimated:YES];
[nav.visibleViewController.view setNeedsDisplay];
I've checked the viewControllers array in the UINavigationController and it has the right viewcontrollers in it (ie it has removed the viewcontroller for the webview).
I also tried putting code in the viewWillAppear of the viewcontroller I'm popping back to, but the method is never getting called.
I'm looking for a way to force the UINavigationController to reload the same way that you can call reloadData on a UITableView.
Any help would be greatly appreciated.
I saw something like this on my app where I was using a navigation bar I added in Interface Builder on the root view of a navigation controller and then programmatically creating the nav bar and its subviews for the second view. When I would pop the second view to return to the first view I would hide the self.navigationcontroller bar which would show the white space underneath until the IB nav bar of the previous view appeared. To fix this I decided to stick with programmatically creating all my navbars which fixed the issue for me.
TL;DR - if you are using both IB and programmatically made navbars this can happen when popping views, stick with one or the other for all the navbars yo
after reading a lot of tutorials and threads here on stackoverflow there is one basic question left in my head.
The structure of my App should be the following:
MainMenu - fullscreen without a navigation bar but 2 buttons (button1 and button2)
Page1 - should appear by pressing button1 and should have a navigation bar at the top with a "back"-button to get back to the MainMenu.
Page2 - should appear by pressing button2 without a navigation bar at the top. Page2 should be a UISplitView. There must be a back button somewhere.
(I think this is where the problem starts, a UISplitView can't be presented modally, can it?)
You should be able to add subpages to Page1.
So how can I do that? I don't need executable code but just a hint on how the structure of my app should be. For example where to add the navigation controller, how the MainMenu looks like.
Thanks in advance!
Are you trying to create an Application for iPad?
Your Application's UI sems inconsistent being First View the only view without navigation Bar.
You will be using standard navigation to navigate to page1 from home page. So you will be adding a navigation Controller with Home View Controller as a Root View COntroller with hidden navigation bar.
eg.
-(void)applicationDidFinishLaunching:...
{
HomeViewController * hvc = [[HomeViewController alloc]init];
UInavigationController * nvc = [[UINavigationController alloc]initWithRootViewController:hvc];
nvc.navigationBar.hidden = YES;
[window addSubView:nvc.view];
}
Then on tap of first Button you will be pushing the Page1 View Controller
-(IBActtion)button1Pressed:(id)sender
{
Page1ViewCOntroller * p1vc = [[Page1ViewCOntroller alloc]init];
[self.navigationController pushViewCOntroller:p1vc animated:YES];
}
In viewWillAppear: method of Page1ViewController unhide the NavigationBar and hide it in the viewWillDisappear: method
Your Page 2 needs to be splitViewController.
Now about Split View, Apple says
The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface.
But as there is no "must" written in the above statement, and since its finally a View Controller in itselt, you should be able to add it on the window or another view.
Try to create a VIewController, with split VIew added on it, and like page1, push the View on the navigation Controller.