Back button doesn't work after pushViewController - ios

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.

Related

IOS/Objective-C/Storyboard: Prevent ViewController From Launching Modally

I want a viewcontroller to launch using a show transition, not modally from the bottom. Normally when I use the following code that's what happens. However, in this case, it is launching as a modal controller from the bottom up. Is there a switch I don't know about or could something be set in Storyboard that is causing this VC to launch modally from the bottom instead of showing?
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEvents =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: importEvents];
[self presentViewController:nav animated:YES completion: nil];
The VC is embedded in a navigation controller.
Should I be using showViewController directly to the targetVC without going through the Nav? Or a pushViewController What is a proper, robust way to show a VC with a show transition?
Thanks in advance for any suggestions.
In the above code you are 'presenting' a new NavigationController from a ViewController. In order to do a push/show transition, that needs to be done on an instance of a NavigationController. If your current ViewController is already in a NavigationController, you can push the new ViewController onto the current NavigationController stack. For Example:
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEventsVC =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
[self.navigationController pushViewController:importEventsVC animated:YES];

navigation controller can't back

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?

How to pop back viewController from SWRevealViewController?

In my app after pressing the login button in my loginViewController, it push to front viewController of my SWRevealViewController. In my RearViewController I have the sign out button. When I press it it should pop to the back viewController again (LoginViewController). But even though I set the button click event like this it doesnt navigate to the loginViewController.
-(void)signOutClick :(id)sender
{
[self performSelectorInBackground:#selector(moveToLoginView) withObject:nil];
}
-(void)moveToLoginView
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
But when I swipe the view it gose to the back view.I want to disable that swipe feature to the back view. And I want to go to the back view when click on the sign out button in my RearViewController. How can I do that? Please help me.
Thanks
I am not sure but instead of using
[self.navigationController popToRootViewControllerAnimated:YES];
try using,
[self.navigationController popViewControllerAnimated:YES];
And to stop swipe gesture you can use code like,
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.revealViewController.panGestureRecognizer.enabled = NO;
}
You need to reset the top view controller if you want to perform these kind of actions off of a click. E.g.
get an instance of the ECSlidingViewController
ECSlidingViewController *slidingController = self.slidingViewController;
get the view controller you wish to be on the top
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"mainViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
set the topViewController property
slidingController.topViewController = nc;
[slidingController resetTopViewAnimated:NO];

Dismissing (or popping) a NavigationController I added manually does not work

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];

properly set up navigation controller as a root for a uitab bar

I am a little bit confused and cannot make things to work.
So, this is my code in my app Delegate.
// If the device is an iPad, we make it taller.
_tabBarController = [[AKTabBarController alloc] initWithTabBarHeight:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 70 : 50];
NSString * storyboardName = #"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
CurrentViewController * tab1VC = [storyboard instantiateViewControllerWithIdentifier:#"Tab1"];
// dummy controllers
CurrentViewController * tab2VC = [storyboard instantiateViewControllerWithIdentifier:#"Tab1"];
CurrentViewController * tab3VC = [storyboard instantiateViewControllerWithIdentifier:#"Tab1"];
CurrentViewController * tab4VC = [storyboard instantiateViewControllerWithIdentifier:#"Tab1"];
[_tabBarController setViewControllers:[NSMutableArray arrayWithObjects:
tab1VC,
tab2VC,
tab3VC,
tab4VC,
nil]];
[_window setRootViewController:_tabBarController];
[_window makeKeyAndVisible];
Then, in my storyboard I have the image below :
So, I have my ViewController and I clicked Embed In > Navigation Controller
I want to have a different navigation controller for each tab.
Inside my CurrentViewController I have this when button is clicked :
- (IBAction)dummyButton:(id)sender {
NSString * storyboardName = #"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UserSettingsSetupViewController *userSettingsSetupController = [storyboard instantiateViewControllerWithIdentifier:#"UserSettingsSetup"];
[[self navigationController] pushViewController:userSettingsSetupController animated:YES];
}
And apparently nothing is pushed into the navigation Controller because nothing opens.
Doing some research, I saw that this is because [self navigationController] or self.navigationController returns nil.
but why is that? Should I add any code? I thought that by doing that from storyboard, it shouldn't be nil? Am I wrong?
A couple of comments. First of all, if you're using a storyboard, don't create view controllers in the app delegate; drag all the controllers you need into the storyboard. There's no need for any added code in the app delegate at all.
Your problem is caused by trying to mix storyboard controllers and code in the app delegate. You are instantiating tab1VC and making that the controller in the first tab -- that controller doesn't "know" anything about the navigation controller you added in the storyboard. If you wanted to do it in code (which I don't recommend), you would need to instantiate that navigation controller instead (it will take care of instantiating its root view controller), and add that as the first item in the viewControllers array.
My advice is do it all in the storyboard. Change the class of the tab bar controller there to AKTabBarController, and set its tab bar height in its init method or viewDidLoad.

Resources