How to exit from UITabBarController to UINavigationController on button click - iphone

I have a MainMenu which navigates me to a TabBarController with 4 views (4 Tabs) in it.
Now I've a button in the 4th view of the TabBarController which OnClick should take me to the MainMenu.
Problem is when I pushViewController (MainMenu) I'm not able to dismiss the TabBarController and also NavigationBar is not visible on the MainMenu!!
Can someone please suggest me how to solve this, Thanks in advance.

Do not use this :
[self.navigationController pushViewController:mainMenuViewController animated:YES];
Try using this:
[self.navigationController popViewController Animated:YES];
Take the reference of your same MainMenu and then push to that view controller

[self.parentViewController.navigationController popViewController animated:YES];
UITabBarController is a container controller and you're adding viewControllers into it like so:
NavController
||
TabBarController
||
DisplayingViewController
since displayingViewController doesn't have a navigationController associated with it but the TabBarController does, you need to call for its parentViewController.

Related

Navigation bar not visible when manual segue

I have a little problem with segues in my app. I am trying to manual PUSH segue. But navigation item/controller/bar is not visible on target controller. When i use button and segue with that button to target view controller, navigation bar IS visible :/
My code is simple:
[self performSegueWithIdentifier:#"MySegue" sender:self];
MySegue is push segue from root view controller of UINavigationController to target controller.
It even did not work with this one
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:[NSBundle mainBundle]];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"TargetViewController"];
[self.navigationController pushViewController:controller animated:YES];
and even if i set top bar (navigation item) in story board manualy
thanks for any help:)
Delete the segue that goes from StaznostiViewController to StaznostViewController. Control-drag from the StaznostiViewController object (in the bar below the view) to the StaznostViewController, NOT from the StaznostiViewController view or from the StaznostiViewController tableview prototype cell. Select Push style. Name your segue whatever you wish.
In your code, in the target-action method that you have defined for your dynamic button(s), this is where you call the method performSegueWithIdentifier.
Also, make sure that in the properties for StaznostViewController, you have the property for Top Bar set to Inferred.
Same thing happened to me. I created a "Push" segue from storyboard, and was calling it from code. Then it lost navigation items on the navigation bar. When I changed the segue to "Modal", then navigation items of the destination view appeared properly. .
try nil sender instead of self:
[self performSegueWithIdentifier:#"MySegue" sender:nil];
hope it works

pushViewController:animated: inside ScrollView

I have a UINavigationController inside it I have a UIViewController handling a ScrollView just to use addSubview: and I am loading several UIViewController into the ScrollView.
I have a button referring to pushViewController:animated: but it does nothing.
I used self.parentViewController and self.presentedViewController but ran into the same issue.
This answer is based off of the title of this question. The question however, is not really a question at all, really.
UIViewControllers must be pushed form a UINavigationController. You cannot use a UIScrollView to push a view. You can use animations to move UIViews within the UIScrollView.
Maybe self.navigationController or self.parentViewController.navigationController is pushing nil .
Initiate a UINavigationController:
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:aViewController];
[self.navigationController pushViewController:nav animated:YES];
[nav release];
Try this. Hope this will help.
I got your problem. What should you do is create button or other view controllers dynamically and add them to UIView and then add this UIView to scrollView. You should add IBaction on runtime to every button and after that your navigation controller will work.
If your UIViewController is child of navigation controller then
[self.navigationController pushViewController:aViewController animated:YES]
will a push a viewcontroller over the present one.
Thats it!.

iPhone - change navigation controller's view, using a button in a subview

I have a navigation controller with a rootview.
The rootview contains buttons, which push new views onto the navigation controller correctly.
However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.
At the moment, it builds and runs, but the new view is not pushed. Any ideas?
Click method on on the ScrollItem button:
MyViewController *newView = [[MyViewController alloc] initWithNibName:#"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
... i guess it is because, self doesn't have a navigation controller, but the rootview does.
Thanks!!
The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.
Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.
So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.

How can I dismiss a pushViewController in iPhone/iPad?

I need to make a button to dismiss the child view controller from a pushViewController. The action is exactly like the left (back) button on the top navigation bar.
How can I dismiss a pushViewController? Which method should I use ?
Thanks.
UINavigationController's popViewControllerAnimated: method should do it.
In my case where [self performSegueWithIdentifier:#"showAllContacts" sender:self]; pushes a new ViewController, in order to close(dismiss) that view controller which has been pushed I use:
[self.navigationController popViewControllerAnimated:YES];
This is called for a custom button which I added to the navigation bar!

Changing UINavigationController from UItabBarController

I have a tabBarController with 4 tabs. In the fist one I need to show an UINavigationController which has a UIView in it. When the user presses a button inside that view I need to display another UINavigationController in tab 1 replacing the old one. Is this possible?
I tried using this code with no luck
UINavigationController *tableNavController = [[UINavigationController alloc] initWithNibName:#"Nav2" bundle:nil];
[[self.tabBarController selectedViewController] setView:tableNavController.view];
This replaces the view but not the controller.
Please help.
Thanks in advance.
Why not just push a fresh viewController onto tab 1's navigationController?