randomp
randomp

Reputation: 357

iOS Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress

I created a UIImageView. And when click on it, a UIActionSheet will pop up.

@IBOutlet weak var avatarImageView: UIImageView!

@IBAction func tapUIImageViewHandler(sender: UITapGestureRecognizer) {
    var popMenu: UIActionSheet = UIActionSheet(title: "Upload user avatar", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Choose from library", "Take photo")
    popMenu.showInView(self.view)
}

func actionSheet(popMenu: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
    println("click at index \(buttonIndex)")
    switch buttonIndex {
    case 2:
        takePhoto()
    case 1:
        chooseFromLib()
    default:
        break
    }
}

But when I run it on simulator, after I click the button on the UIActionSheet, I get

Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

Can anyone help me with that? Thanks!

Upvotes: 0

Views: 2897

Answers (2)

miOS
miOS

Reputation: 1377

Please implement small delay while presenting actionsheet.

[self performSelector:@selector(presentActionsheet) withObject:nil afterDelay:0.2f];

Upvotes: 1

valfer
valfer

Reputation: 3545

In my opinion, it is a bug (you should file a bug report. I tested a simpler project (with only a button and an action opening the ActionSheet, no delegate) in the following cases:

  • Swift XCode Beta 4 -> warning
  • ObjC XCode Beta 4 -> warning
  • ObjC Xcode 5.1.1 -> OK

By the way I remember you that since iOS8 ActionSheet is replaced by UIAlertController with UIAlertControllerStyle set to ActionSheet. But it is also true that we must continue to use ActionSheet, especially because we all probably still target version < 8.

Upvotes: 0

Related Questions