Warning: Attempt to present ModalTableViewController on MainTableViewController which is already presenting (null)
Solution 1
I'm not on swift yet, but for Objective-C, I ended up wrapping the presentViewController call in a performSelector call.
-(void) present
{
[self performSelector: @selector(ShowModalTableViewController) withObject: nil afterDelay: 0];
}
-(void) ShowModalTableViewController
{
[self presentViewController: ctrlModalTableViewController animated: true completion: nil];
}
Solution 2
I had this issue because I was trying to perform segue / present from within:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
I changed it to:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
and it fixed it!
Solution 3
This will work also:
dispatch_async(dispatch_get_main_queue(), ^ {
[self presentViewController:vc animated:YES completion:nil];
});
Solution 4
It appears this is true of presenting anything over a popover. The reason all of the previous responses work is likely because whatever action is being taken happens before the popover (or activity sheet, or similar) is dismissed.
If you can, try dismissing the popover first, then presenting your modal.
Solution 5
Easily just add this code snippet into ViewDidLoad()
of your main uiviewcontroller
definesPresentationContext = true
![derdida](https://i.stack.imgur.com/2drgw.png?s=256&g=1)
derdida
Software Developer with Experience in PHP, Swift, Objective C, Javascript, C#.
Updated on July 09, 2022Comments
-
derdida almost 2 years
I have a problem with a popover. If I tap on a cell I will load a popover to select more details. Everything works fine, but when I press my cell again I receive every time the following message:
Warning: Attempt to present ModalTableViewController... on MainTableViewController... which is already presenting (null)
If I tap on another cell I will not get this Warning. Only if a tap the same row again.
I tried lots of things but I am not able to solve this problem. I load my popover with like this:
var popover: UIPopoverController! var popoverContent: ModalTableViewController!
and on my cell tap:
popoverContent = self.storyboard.instantiateViewControllerWithIdentifier("ModalTableViewController") as ModalTableViewController popoverContent.selectedQuestionID = indexPath!.row popover = UIPopoverController(contentViewController: popoverContent) popover.delegate = self popover.presentPopoverFromRect(currentCell.LabelCellTitle.frame, inView: currentCell.LabelCellTitle.superview, permittedArrowDirections: UIPopoverArrowDirection.Left, animated: true)
And to dismiss
func popoverControllerDidDismissPopover(popoverController: UIPopoverController!) { popover.dismissPopoverAnimated(false) // just to check self.popover = nil self.popoverContent = nil }
Any ideas?
Edit:
If I check with:
if(self.popoverContent == nil) {
before opening it, I'll find out that it's not nil when I tap the same cell again.
Edit again:
I have the same problem if I create it with a little different setup:
Custom 1x1px Button. Connect popover with segue. On cell tap move button to cell and open popover.
So there is no code for opening the popover, only with storyboard editor.
I get the same error message (sometimes) just if I tap the same popover again.
-
Travis M. almost 10 yearsNot sure why this was down-voted. This actually fixed the issue for me.
-
Josip B. over 9 yearsI don't know what is happening with iOS but I'm glad there are people like @Acace which saved my day!
-
lihudi over 9 yearsI had an app that worked perfectly in IOS7 but had this issue in IOS8. This tip fixed it.
-
Zhang over 9 yearsdispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ /* put code to execute here */ }); also fixed it on iOS 8 for me, in case you don't want to create a new method just to call the same code.
-
MartinR over 9 yearsThis was the case for me. Simple solution to a dumb issue.
-
Paludis over 9 yearsThis fixed my issue as well.
-
Thiru over 9 yearsIf in case you are presenting from within ActionSheet button click - try @Steve's answer for using didDismissWithButtonIndex
-
Erik Engheim over 9 yearsThis solved a similar problem for me. However I don't understand why this works. Why do I need to do this? Any links to anything that will give more background info?
-
Elijah over 9 yearsIt runs presentViewController on a different thread, so there is no longer a conflict. As to why - because Apple must have changed the way they are handling these things behind the scenes.
-
Erik Engheim over 9 yearsDifferent thread? I am not following. dispatch_get_main_queue() should give you the main UI thread right, which is what I am calling this from.
-
Elijah over 9 yearsYes, it is the main thread, but it's being dispatched asynchronously, so it's not preventing the other activivities from happening. Here is some discussion on GCD jeffreysambells.com/2013/03/01/…
-
Vipin Johney over 9 yearsDoes this solution cause any other issue which needs to be handled?? Just asked
-
Steve over 9 yearsNot that I have come across.
-
Daniel over 9 yearsThe above does WORK AROUND the problem/bug in iOS 8. But it's a hack way to do it. Steve's answer to switch to using didDismissWithButtonIndex: is the better solution. LOOK AT THE STEVE'S ANSWER. It's less work and much less fragile.
-
Julian about 9 yearsI think the solution you proposed might work but has to be consider as a nasty hack. it is not solving the source of the problem which is showing pop up before dismissing the previous one. Make sure you have dismissed the old one and then present the new one. It works as it adds a change to the next run on the main run loop
-
Martin about 9 yearsThis should be the correct answer. Currently accepted is a hack, this one is clever solution.
-
aryaxt about 9 yearsHere is another solution and explanation on why this is happening. stackoverflow.com/questions/24942282/…
-
nikhil.thakkar over 8 yearsJust for the records, if you have already defined a segue in storyboard on tap of a button or cell tap and you fire the segue programmatically as well, then this can cause the said error.
-
Raj Tandel about 8 yearsThis fixed the issue for me. but what difference does it make if we use clickedButtonAtIndex or didDismissWithButtonIndex ? can anyone please explain.
-
Steve about 8 years@RajTandel Been a while but I think clickedButtonAtIndex might not be called on the main thread (why most other answer suggest dispatching back to main queue).
-
Mantas Laurinavičius almost 8 yearsUiActionSheet is of UIPopoverController class and prevents another pop over view to be pushed until it is removed. I knew it was the case and this answer is what I am looking for.
-
Mihir Oza over 7 yearsI got issue in iPad but after use your code it worked for me in IOS 9.
-
AndyH over 7 yearsI have tried every possible solution, but this was the only one that worked. Thanks
-
Deeper almost 7 yearsthanks so much, it saved my day, i found this issue happened on my iPad but iPhone are no problem at all