Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

ios - Warning: Attempt to present ModalTableViewController on MainTableViewController which is already presenting (null)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...