Can not go back on main UIViewController after going to UITableViewController - ios

I've this sequence of controllers in storyboard
UIViewController embeded in navigation controller => button pressed(on UIViewcontroller) get UITableViewController(embeded in navigation controller) => row selected get another UITableViewController => row selected UIViewController
Now the problem is when I go to first UITableViewController I can not go back to Main UIViewController.
Do I have to add bar item button or is there other way.
Please help.
UPDATE -
Got it working, had embeded UITableViewController in navigation controller that's why it was not showing main view controller

If you are not hiding navigation bar or bar button then there is by default a button for back else Try this code to go back
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] animated:YES];

Related

Multiple segues remove navigation bar in view controller

I have a view controller that has a navigation bar. It is the root view controller of the navigation controller. I have another view controller that can be segued from a button on the first controller. Up to this point, everything works fine; there are navigation bars on both view controllers.
However, from the second view controller, I want to be able to segue back to the first controller. When doing this, it removes the navigation bar from both of the view controllers.
How can I get the navigation bar on both view controllers with buttons as transitions? Thanks!
Implement below method in your both viewcontroller,
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
You may hiding navigationbar somewhere.
Try this in storyboard:
Select the navigation controller -> Attributes Inspector -> Under Navigation controller and Bar Visibility leave the "Show navigation bar" blank

Changing view controller to tab bar controller

I have a tab based application with 2 tabs (HomeViewController and SettingsViewController).
On the SettingsViewController I have a button that will take the user to a third view (ChangeSomeSettingController).
On that third view, I have a TableView with this function
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
...
let settingsViewController = self.storyboard!.instantiateViewControllerWithIdentifier("SettingsViewController") as! SettingsViewController
self.presentViewController(settingsViewController, animated:true, completion:nil)
}
This will move the user back to the SettingsViewController. However, I am not able to get the tab bar to display at the bottom of the screen like it is when I first load the application.
How can I go back to the SettingsViewController and keep the tabs at the bottom of the screen?
First of all, presentViewController:animated:completion: will present SettingsViewController modally. What you need is a UINavigationController flow.
1) Add create UITabBarController
2) Select the item(UIViewController) that will has a UINavigationControler flow.
3) Delete it
4) Add UITableViewController
5) Add the new UITableViewController to the UITabBarController
6) Select the UITableViewController and embed in(Editor > Embed In > Navigation Controller) to a Navigation Controller.
7) Add a UIViewController and add a segue(Show) between UITableViewController and UIViewController
8) The result final result should be something like this:
In ChangeSomeSettingController, if you pushViewController from SettingViewController, you should call
navigationController?.popViewControllerAnimated(true)
or if you want to back to SettingViewController
//back to root view controller from navigation
navigationController?.popToRootViewControllerAnimated(true)
// you should call to tabbar view controller
UITabbarViewController *tabbarVC = (UITabbarViewController *)[UIApplication sharedApplication] delegate].window.rootViewController;
[tabBarController setSelectedIndex:1]; // 1 is index of SettingViewController
This's example for me, with your problem you can modify to adapt your requirement. hope this help for you.
This line:
self.presentViewController(settingsViewController, animated:true, completion:nil)
will not move back the user to settings VC, it will present a new instance of the settings VC, which ofcourse covers the tab bar.
You need to push the VC when you select the tabs, so you don't have to present them again if you want to go back.
If you don't want a navigation controller, then you should present the tab bar controller instead of settings vc.

Why TabBar hides after the segue?

I have the next structure:
* TabBarController
- ViewController with TableView
- ViewController
When I select any row on the TableView, the segue forwards me to the ViewController. On the ViewController with the TableView, I see the BottomBar, but after the segue it disappears.
How can I keep it on my ViewController? I've even putted the last ViewController in NavigationController, but it did not help me, too.
How can I fix it?
Your hierarchy should look like this:
* TabBarController
- NavigationController
- ViewController with TableView
- ViewController
Using a Show segue with an UINavigationController pushes the destination view controller onto the navigation stack. However, most other view controllers present the view modally (i.e. by sliding over the source view controller) with Show, which is why your tabbar disappears.
uncheck hide bottom bar when pushed from your view controller in story board

UITabBar disappears when NavigationController pop the view back to the said ViewController

I have a UITabBar on a UIViewController, attached from the Interface Builder, which is working fine, until I have a button that pushes another ViewController to the screen (ex: Login screen) via NavigationController.
After the other ViewController is popped, the screen returned to the original ViewController, but the TabBar is disappeared. How can I fix this? Thanks.
-(void)viewWillAppear:(BOOL)animated{
[self.tabBarController.tabBar setHidden:NO];
}
use This in popped controller

popViewController not working with storyboards

I create a UINavigationController (as a initial screen) and connect them with my UITableViewController (as a root).
Next, I create another UINavigationController and connect with my UIViewController. Inside my UITableViewController I connect my first cell with UINavigationController (That was connected with my UIViewController) (Segue -> show).
When I run the project my table appears, when I select my first row, my UIViewController appears. Thats great!
When I was in my UIViewController the back bar button doesn't appears, in my case I create a left bar button, that will run a function to dismiss that view and go back to my UITableViewController, for that I use many codes:
-(void)back{
NSLog(#"Called");
[self.parentViewController.navigationController popViewControllerAnimated:YES];
}
-(void)back{
NSLog(#"Called");
[self.navigationController popViewControllerAnimated:YES];
}
-(void)back{
NSLog(#"Called");
[self.navigationController popViewControllerAnimated:YES];
}
But all of they doesn't works and my view don't dismiss, how can I solve this problem?
The problem is that your navigation controller, that you call from your table view cell, has only a single view controller (yours) on its navigation stack. So it cannot pop anything from this stack, else the stack were empty.
What you have to do instead is to dismiss the navigation controller itself.
I think that the solution would be to remove the second navigation controller. Since the TableView is already embedded inside a Navigation Controller, the show segue to the UIViewController must be directly connected to it.

Resources