Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about storyboards and pushing programmatically ios Objective C

I am really confused about the relationship between storyboards and pushing to views programmatically.

I am using SWRevealViewController to display a menu of items.

If I push to the storyboard using

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"PhotosViewController"];
[self presentModalViewController:controller animated:YES];
[self.navigationController pushViewController:controller animated:YES];

All of the information in my storyboard is displayed but there is no "back" button to the SWRevealViewController.

If I push to the view controller using

PhotosViewController *frontViewController = [[StreamScreen alloc] init];
    newFrontController = [[UINavigationController alloc] initWithRootViewController:frontViewController];

Then I can view everything that I have added programmatically but nothing from the storyboard.

My question is how can I access things from both storyboard and things Ive added programmatically.

like image 515
AB567 Avatar asked Oct 20 '22 12:10

AB567


1 Answers

if you present the view controller then it will not give you default back button because when you present a controller it will not added in navigation stack of NavigationController so it won't give you that option.

If you want push controller do not use presentModalViewController.

Try like below

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"PhotosViewController"];
[self.navigationController pushViewController:controller animated:YES];

and if you want to present controller then create manually add a back button like we have default in navigation back button and on it's click write below code to dismiss the controller.

[self dismissViewControllerAnimated:YES];

Hope this helps you.

like image 188
Malav Soni Avatar answered Oct 22 '22 04:10

Malav Soni