I'm using the presentViewController:animated:completion:
method to go to another view controller.
This is my code:
AddTaskViewController *add = [[AddTaskViewController alloc] init];
[self presentViewController:add animated:YES completion:nil];
This code goes to the other UIViewController
but the other controller is empty. I've always been using storyboards but now I need this to be done in code.
This question is related to
ios
objective-c
uiviewcontroller
uistoryboard
presentviewcontroller
LandingScreenViewController *nextView=[self.storyboard instantiateViewControllerWithIdentifier:@"nextView"];
[self presentViewController:nextView animated:YES completion:^{}];
your code :
AddTaskViewController *add = [[AddTaskViewController alloc] init];
[self presentViewController:add animated:YES completion:nil];
this code can goes to the other controller , but you get a new viewController , not the controller of your storyboard, you can do like this :
AddTaskViewController *add = [self.storyboard instantiateViewControllerWithIdentifier:@"YourStoryboardID"];
[self presentViewController:add animated:YES completion:nil];
If you are using Storyboard and your "add" viewController is in storyboard then set an identifier for your "add" viewcontroller in settings so you can do something like this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"NameOfYourStoryBoard"
bundle:nil];
AddTaskViewController *add =
[storyboard instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];
[self presentViewController:add
animated:YES
completion:nil];
if you do not have your "add" viewController in storyboard or a nib file and want to create the whole thing programmaticaly then appDocs says:
If you cannot define your views in a storyboard or a nib file, override the loadView method to manually instantiate a view hierarchy and assign it to the view property.
Here is how you can do it in Swift:
let vc = UIViewController()
self.presentViewController(vc, animated: true, completion: nil)
Try this code:
[self.navigationController presentViewController:controller animated:YES completion:nil];
The best way is
AddTaskViewController * add = [self.storyboard instantiateViewControllerWithIdentifier:@"addID"];
[self presentViewController:add animated:YES completion:nil];
You need to set storyboard Id from storyboard identity inspector
AddTaskViewController *add=[self.storyboard instantiateViewControllerWithIdentifier:@"storyboard_id"];
[self presentViewController:add animated:YES completion:nil];
Try the following:
NextViewController *nextView = [self.storyboard instantiateViewControllerWithIdentifier:@"nextView"];
[self presentViewController:nextView animated:YES completion:NULL];
Source: Stackoverflow.com