Push to a UIViewController from a presentViewController - ios

I want to push to a new viewcontroller from a presented viewcontroller. I don't want to dismiss the presented viewcontroller. I want the new viewcontroller to come over the presented viewcontroller.
Can anybody tell me how to do that.

You do not push form the presented controller so the best option is
First you have to dismiss the controller without animation and then in the method of -(void)viewWillApper you can easly push to the controller where you want to push.

You can do by using UINavigationController like
UINavigationController *vcObject = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"YourViewController"];
[self.navigationController presentViewController:vcObject animated:YES completion:NULL];
Now you can easily push or pop to other ViewController like you want.Thankyou

Open your modalView controller as a new rootViewController :
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextViewController];
[self.navigationController presentViewController: navController animated:YES completion:nil]

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

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

Redirect to particular view controller when getting local notification

I am trying to implement local notification and its working fine but my problem is when my application is in foreground and I got the push from the server it will alert me but when I tap on that alert and trying to redirect on my home view controller with the using this simple code in app-delegate file
- (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView
{
UIStoryboard *storyboard = [[self.window rootViewController] storyboard];
HomeViewController *obj_home=[storyboard instantiateViewControllerWithIdentifier:#"Home"];
UINavigationController* navigationViewController_test=[[UINavigationController alloc]initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:#"Home"]];
[navigationViewController_test pushViewController:obj_home animated:YES];
}
With this code it will show only black screen,can any one tell me where i making the mistake? and yes for the local notification alert I am using third party tool (CMNavBarNotificationView) and using its delegate method (didTapOnNotificationView)
You need to link up the navigationcontroller with a viewcontroller currently in the navigation stack. Here in the below code I am using the rootviewcontroller to present/push the HomeviewController, you can replace it with any controller that you want.
- (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView
{
UIStoryboard *storyboard = [[self.window rootViewController] storyboard];
HomeViewController *obj_home=[storyboard instantiateViewControllerWithIdentifier:#"Home"];
// either present the navigation controller as a modal
UINavigationController* navigationViewController_test=[[UINavigationController alloc]initWithRootViewController:obj_home];
[self.window.rootViewController presentViewController:navigationViewController_test animated:YES completion:^{}];
// OR push the home view. Here my rootViewController is a navigation controller, so I am pushing the home view directly from it. You can push it from any of the controller that is in the current navigation controller stack.
[(UINavigationController *)self.window.rootViewController pushViewController:obj_home animated:YES];
}
Hope this helps.

iOS presented UINavigationController gets dismissed after it performs a popViewController

In my app i present a UINavigationController modally with a UIViewController as its rootViewController. I do it in form style. I added a second UIViewController which is also in form style and i can push to it fine. However when i perform a popViewController action after the second UIViewcontroller gets popped onto the first, the whole modally presented UIViewController gets dismissed. However i don't perform any dismissing and the dismissing function doesn't get triggered by accident either.
Any ideas why it's happening?
Sincerely,
Zoli
EDIT:
That's how i'm presenting the modal viewcontrollers with a navcontroller:
if(!welcomeScreenAlreadyPresented) {
welcomeScreenViewController = [[WAWelcomeViewController alloc]init];
}
welcomeScreenNavController = [[UINavigationController alloc]initWithRootViewController:welcomeScreenViewController];
[welcomeScreenNavController setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[welcomeScreenNavController setModalPresentationStyle:UIModalPresentationFormSheet];
[welcomeScreenNavController setNavigationBarHidden:YES animated:NO];
[self.navigationController presentViewController:welcomeScreenNavController animated:YES completion:nil];
That's how i'm navigation in WAWelcomeViewController.m
registerViewController = [[WARegisterViewController alloc]init];
[self.navigationController pushViewController:registerViewController animated:YES];
And in WARegisterViewController.m that's how i pop back
[self.navigationController popViewControllerAnimated:YES];
What you need to do is put the viewController you want to push inside another UINavigationController.
registerViewController = [[WARegisterViewController alloc]init];
UINavigationController *modalNavigationController = [[UINavigationController alloc] initWithRootViewController:registerViewController]; // autorelease if you are not using ARC
[self presentViewController:navController animated:YES completion:^{}];
You might want to add the modalNavigationController as a property to later call popViewControllerAnimated: on it.

Adding a UINavigationController to an existing UINavigationController

simple question... My app starts out with a UINavigationController with a UIViewController (of course), but when a button is pressed, I want another UINavigationController to be presented.
Would I do:
[self.navigationController presentViewController:AnotherNavigationController animated:YES completion:nil];
or:
[self presentViewController:AnotherNavigationController animated:YES completion:nil];
Both ways work... But I'm not sure which one is correct... And also, I can't seem to get the BarButtonItem's to appear once that navigationcontroller is presented
PS. The navigationcontroller has a tabbarcontroller with two tab views in it
Thanks in advanced!
Try this:
[self.navigationController pushViewController:AnotherNavigationController animated:YES];
Use push segue instead.
try this code:
after login sucess
UIStoryboard *Story_TabController = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil]
UIViewController *class1 = [Story_TabController instantiateViewControllerWithIdentifier:#"Feed_ViewController"];
UIViewController *class = [Story_TabController instantiateViewControllerWithIdentifier:#"FindFriends_ViewController"];
UINavigationController *nav_profile=[[UINavigationController alloc]initWithRootViewController:class1];
UINavigationController *nav_post=[[UINavigationController alloc]initWithRootViewController:class2];
Tab_controller.viewControllers=[NSArray arrayWithObjects:nav_profile,nav_post, nil];
Tab_controller.selectedIndex=0;
[self.navigationController pushViewController:Tab_controller animated:YES];

Resources