Reputation: 2272
I am using Storyboard and I have 20 View Controllers and they all have the same "Settings" button in the corner. On clicking it performs a Segue to another VC which I simply dismiss to go back to the original.
The problem is I am going to have to ctrl-drag from ALL VCs to this one which makes for a very messy Storyboard. Is it possible to add them pragmatically?
I have tried to present them instead but when I dismiss I simply get a black screen. Using the below;
settingsViewController *settingsVC = [[settingsViewController alloc]init];
[self presentViewController:settingsVC animated:YES completion:nil];
And then I dismiss like this;
[self dismissViewControllerAnimated:YES completion:nil];
Upvotes: 0
Views: 292
Reputation: 77641
First, by creating the settingsVC using alloc init you are bypassing the storyboard altogether which is why you get a black screen as the storyboard adds the UI to it.
However, you can still do it without segues at all.
First thing to do, in the storyboard. Go to the settings controller and in the property inspector give it an identifier. Something like "SettingsViewController".
Now in you settings button action...
- (IBAction)settingsButtonPressed
{
UIViewController *settingsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];
[self presentViewController:settingsViewController animated:YES completion:nil];
}
This will use the storyboard to create the view controller so that you can then present it with all its UI in place.
Upvotes: 2