UINavigationController pushes from controllerA to controllerB,
but the navigation bar still show controllerA's . (custom content is controllerB,the navigation bar is controllerB's is right result)
Here is few lines from my method
MKMCComboListTVC *controllerVC = [[MKMCComboListTVC alloc] init];
[self.navigationController showViewController:controllerVC sender:nil];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MYAddShopTVC *controllerVC = [mainStoryboard instantiateViewControllerWithIdentifier:#"MYAddShopTVC"];
controllerVC.nameList = transNameList;
[self.navigationController showViewController:controllerVC sender:nil];
then when I click back button, controller is not poped back. It shows ViewController from controllerB to controllerC, custom content is in the controllerC, the navigation bar is controllerA's. In short it can push next controller ,but can't back. so navigation bar doesn't match custom content.
How can I fix this?
Related
I have the following layout on my story board:
When I click on the button I load the blue view controller:
- (IBAction)blue:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
BlueViewController *blue = [storyboard instantiateViewControllerWithIdentifier:#"BlueViewController"];
[self presentViewController:blue animated:YES completion:nil];
}
The blue view controller has navigation bar embed. But doesn't show on either the blue viewcontoller or the pink view contoller:
My question to you guys is what I'm doing wrong? or why does the view controller is not showing ?
Give the navigation controller for blue VC a storyboard ID, and present that instead of blue VC.
If you present a VC, even though it has a navigation controler it doesnt show up as you present only the view cotroller.
- (IBAction)blue:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *blueNavVC = [storyboard instantiateViewControllerWithIdentifier:#"BlueViewControllerNavigationController"];
[self presentViewController: blueNavVC animated:YES completion:nil];
}
And when you want to move from blue to pink, you need to push to pink controller as pink is part of the blue navigation controller stack!
If you want to present on a view controller then you have to add a custom view in in top of your controller cz it's on the your navigation controller. If you push a controller then you don't need the above. You will find the same navigationbar to all. Cz It's within your navigation controller stack.
This is how I am pushing a UIViewController :
[tabController setSelectedIndex:0];
UINavigationController *navController = [tabController selectedViewController];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
NotificationViewController *notificationController = (NotificationViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"NotificationViewController"];
[navController pushViewController:notificationController animated:YES];
navController.navigationBarHidden = NO;
When NotificationViewController is visible and I tap Back button, nothing happens. The previous UIViewController had a gesture in UINavigationBar but I have removed it in the UIViewController's viewWillDisappear. But still the NotificationViewController's Back button doesn't work.
You probably call the pushViewController before the view is visible.
Make sure you don't call your pushViewController in the viewDidLoad.
Your pushViewController should be used only after viewDidAppear is called if you want your navigation controller to work properly with the back button. Otherwise, the navigation controller will add the title to the previous view controller without the redirection link.
In my AppDelegate I have the following code which is executed after receiving a notification:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navigationController = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:#"VideoPlayback"];
VideoPlaybackViewController *videoPlaybackViewController = (VideoPlaybackViewController *)[navigationController topViewController];
videoPlaybackViewController.publishing = YES;
[(UINavigationController*)self.window.rootViewController pushViewController:navigationController animated:NO];
That successfully brings up the new ViewController and apparently adds it to the navigation stack, since I can use the back button on the navigation bar to go back and subsequently dismiss the view controller.
The problem is, I don't want to use the navigation bar. In fact, I would like to hide the back button. Unfortunately, when I try to dismiss the viewcontroller using the method(s) it should use, it does nothing. I've tried using both of these to dismiss the view controller:
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
What am I doing wrong? Thanks.
You're trying to push a navigation controller into a navigation controller, which won't end well.
[(UINavigationController*)self.window.rootViewController pushViewController:navigationController animated:NO];
probably needs to be changed to:
[(UINavigationController*)self.window.rootViewController pushViewController:videoPlaybackViewController animated:NO];
I am new to iOS as my project depends on both navigation and the UITabBar controller.I have done the following steps
UITabBar contains 4 buttons and navigation bar contains 2 buttons i.e is common to all the screens
1)first i have taken the UITabBar controller and added four buttons to it
2)For each button to the UITabBar i have added the navigation controller
When i click the tabbar buttons all the views are showing fine and coming to UITabBar bar buttons I am facing the problem as below
suppose I am in UITabBar screen "A" and i clicked the navigation bar button i got the navigation screen ex as "Navscreen"that means now "A" contains
"Navscreen" when i clicked tabbar button "B" and came back to UITabBar button "A" still its showing the "Navscreen"
To avoid such cases in the "Navscreen" view controller i have added the code as below in the view will appear
-(void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
NSUInteger indexOfTab = [tabBarController.viewControllers
indexOfObject:viewController];
NSLog(#"Tab index = %u (%u)", indexOfTab);
if (indexOfTab==0)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
FirstViewController *firstview =
(FirstViewController *) [storyboard
instantiateViewControllerWithIdentifier:#"home"];
[self.navigationController pushViewController:firstview
animated:YES];
}
else if (indexOfTab==1)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
secondviewcontroller *secondview =
(secondviewcontroller *) [storyboard
instantiateViewControllerWithIdentifier:#"Medremainder"];
[self.navigationController pushViewController:secondview animated:NO];
}
if (indexOfTab==2)
{
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:#"Main" bundle:nil];
mymedView *mymed_view =
(mymedView *) [storyboard
instantiateViewControllerWithIdentifier:#"mymed"];
[self.navigationController pushViewController:mymed_view
animated:NO];
}
if (indexOfTab==3)
{
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:#"Main" bundle:nil];
Event_view *event_view =
(Event_view *) [storyboard
instantiateViewControllerWithIdentifier:#"Event_view"];
[self.navigationController pushViewController:event_view
animated:NO];
}
}
But in this case when click "Navscreen" its working and when I click the UITabBar "B" iam able to get the UITabBar screen.If i click again UITabBar "A" i can see "A" and when i click the UITabBar button "B" app is crashing.AS i am new to ios please help me with the possible solution if i make any thing wrong please suggest with the correct solutions.
In your didSelectViewController:, you seem to be pushing new controllers onto self.navigationController multiple times? Each time you select a tab this code will push another controller loaded from storyboard on top of what is already there. This is probably what is messing up your navigation items.
Should you not just be allocating separate navigation controllers once to each tab so this is all automatic?
In storyboard/code allocate separate navigation controllers for each tab. In each navigation controller, create it with a root controller based on what you are loading from storyboard for each tab. You only need to create this once somewhere in your main controller. Then allocate the navigation controllers to separate tabs in storyboard or in code set the array of controllers to be an array of your created navigation controllers.
It should then all be automatic without you needing to implement didSelectViewController: at all since each tab will simply cause the appropriate navigation controller to be presented and its associated navigation bar.
I'm trying to arrive at tab bar C on IBAction from a button the newViewController. But when I arrive the tab bar controller shows A's view instead of C's view. If using
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"MyInitialViewController"];
[vc presentModalViewController:navController animated:NO];
I end up creating view of C tab bar with no tabbar options and navigation bar like this
Any help would be greatly appreciated! thank you
If you use storyboards and want to keep the navigation bar and tab bar, you should use
[self.navigationController performSegueWithIdentifier:#"MyInitialViewController" sender:self];
instead of using modal presentation