Reputation: 626
I am trying to present a view controller modally from another view controller that is the second view inside UINavigationController. But it keep giving error and crashing. Application tried to present modally an active controller
I dont know what does it mean. Following is the way how i am calling.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
FBPreviewPostViewController *previewPostViewController = [storyBoard instantiateViewControllerWithIdentifier:@"FBPreviewPostViewController"];
previewPostViewController.delegate = self;
previewPostViewController.selectedImg = selectedImage;
[self presentViewController:previewPostViewController animated:YES completion:nil];
Thanks
Upvotes: 1
Views: 10018
Reputation: 144
The error indicates that the view controller is presented twice, which is not allowed.
I don't know much about Storyboards and your app, perhaps FBPreviewPostViewController
has been presented by storyboards. You can check whether it is in view hierarchy by checking viewController.isViewLoaded && viewController.view.window
is true or not.
BTW, you are using storyboards, why don't use segue?
Upvotes: 2
Reputation: 1242
Can you try following code
NSString *stbName = [[NSBundle mainBundle].infoDictionary objectForKey:@"MainStoryboard_iPhone"];
UIStoryboard *Mainstoryboard = [UIStoryboard storyboardWithName:stbName bundle:nil];
FBPreviewPostViewController *previewPostViewController = [Mainstoryboard instantiateViewControllerWithIdentifier:@"FBPreviewPostViewController"];
previewPostViewController.delegate = self;
previewPostViewController.selectedImg = selectedImage;
[self presentModalViewController:previewPostViewController animated:YES];
Upvotes: 1