Attempting to load the view of a view controller while it is deallocating … UIAlertController

后端 未结 7 2012
走了就别回头了
走了就别回头了 2020-12-24 01:55

I am building with the release version of Xcode 7.0. No storyboards, just nib files.

I have a single UINavigationController created by the app delegate

7条回答
  •  心在旅途
    2020-12-24 01:56

    In my case, in Swift 3, I had missed the code below after adding the action

    presentViewController(theAlert, animated: true, completion: nil)
    

    So, the working code is as below

    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    
         if (editingStyle == UITableViewCellEditingStyle.Delete) {
    
            let title = "Delete ????"
            let message = "Are you sure you want to delete this item?"
    
            let theAlert = UIAlertController(title: title,
                                       message: message,
                                       preferredStyle: .ActionSheet)
    
         let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
         theAlert.addAction(cancelAction)
    
         let onDelete = UIAlertAction(title: "Delete", style: .Destructive, handler: { (action) -> Void in
         self.items.removeAtIndex(indexPath.row)
         self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    
         })
         theAlert.addAction(onDelete)
            presentViewController(theAlert, animated: true, completion: nil)
         }
         }
    

    //Note I was using a sample array

    var items = ["iPhone", "iPad", "Mac"]
    

提交回复
热议问题