I'm trying to push a new view controller on screen with an animation but this doesn't work. I use this code :
PhotosViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:vcID];
[self.navigationController pushViewController:controller animated:YES];
But even by setting animated:YES there is no animation.
Do you know what can cause this ?
Thanks in advance
Related
I want to be able to show a viewController when a button is pressed.
I don't want to use a navigation controller anymore, is there a way to display it using a modal?
Here is how I am currently showing the viewController:
- (void) editButtonDidClicked: (UIButton *) button {
EditViewController *viewController = [EditViewController getInstanceWithTag:button.tag];
[self.navigationController pushViewController:viewController animated:YES];
}
You can try below code
I assume that you are using storyboard.
UIStoryboard *board = [UIStoryboard storyboardWithName:#"name" bundle:nil];
viewController *controller = [board instantiateViewControllerWithIdentifier:#"Identifier"]; // Identifier is define in storyboard
[self presentViewController:controller animated:YES completion:nil];
Please check out this link if you are still facing the problem.
Hope this helps you.
After some time searching for an answer, I have to admit that i'm pretty confuse with this case.
At my job, I'm asked to do something really specific :
I have to present a UIViewController on a previous UIViewController, actually, the current ViewController dismiss itself before the second appear. That give the whole thing a funny animation that a ViewController goes down and another rise from the bottom after this. But... It's not really "pro" and, we're able to see the rootViewController behind the scene during the animation.
So, I have to precise that there is NO NavigationController, that would have made this a lot easier in my opinion, so I'm forced to do it with two UIViewController, and there is my actual code :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"userViewController"];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:controller animated:YES completion:^{
[self dismissViewControllerAnimated:YES completion:nil];
}];
It is call right after a button is pressed, so there is no problem with the actual ViewController viewDidLoad or viewDidAppear I think.
But each time this code runs, I get the following error :
[1163:17641] Warning: Attempt to present <UserViewController: 0x7b0f0a00> on <EIHomeViewController: 0x7b0d2a00> whose view is not in the window hierarchy!
I don't really know how I could manage to keep a trace of the current UIViewController to dismiss it in the next ViewController viewDidAppear to be sure there will be no "blackout" on the screen.
Thank you for your help in advance!
Try this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"userViewController"];
[self dismissViewControllerAnimated:NO completion:^{
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:controller animated:NO completion:nil];
}];
I'm new on IOS platform and after study a little about how does it works, i had one doubt about how to call a new class/view and overlay the current view when a button is pressed. In android i do:
Intent intent = new Intent(a.class, b.class);
startActivity(intent);
Searching on internet, i noticed that i have to use navigation bars to do it. I start an app with tab bar controller and putted a navigation controller. I used the code below:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:#"Dicas"];
[self.navigationController pushViewController: myController animated:YES];
and the return:
There is a way to overlay the current view? I always have to use navigation bars to call another class (use bottom e upper controllers will make my app ugly)?
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To hide tab bar:
yourViewController.hidesBottomBarWhenPushed = YES;
You can also call another viewController by using presentViewController function of a viewController class.
[self presentViewController: myController animated:YES completion:nil];
As you said u want to overlay your current view so not sure but You can show your view controller using model view like this
yourViewController *secView = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
[secView setModalPresentationStyle:UIModalPresentationPageSheet];//u can use different UIModalPresentationStyle
[secView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.navigationController presentViewController:secView animated:YES completion:nil];
Above one will show your view controller over existing view controller, once presented you need to make provision to dismiss this modal view.
Simple way to present new class or ViewController like this..
ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:view animated:YES completion:nil];
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.
I was using that method for pushing another UIViewController in if condition :
initViewController *MW = [initViewController alloc];
MW = [self.storyboard instantiateViewControllerWithIdentifier:#"init"];
[self.navigationController pushViewController:MW animated:YES];
Now i've changed my architecture and i just removed my Navigation controller. That's why , these steps will not help me any longer due to no NavigationController exist. Now how can i push another ViewController without pressing button -(IBAction) . I just wanted to use it in Storyboard.
Regards.
FYI : without UINavigationController You can't push to another Controller . You can produce a Controller using
PresentViewController
[self presentViewController:objPortrit animated:YES completion:^{ }];
For Ex:
initViewController *MW = [initViewController alloc];
MW = [self.storyboard instantiateViewControllerWithIdentifier:#"init"];
[self presentViewController:MW animated:YES completion:^{
}];
EDIT:
For your comment :
after producing the ViewController with PresentViewController, You need to dismiss it to produce another ViewController .
You can get over from this , something like this in their respective ViewController Use his method. :
-(void)viewDidDisappear {
[self dismissModalViewControllerAnimated:YES];
}