滑动以删除不在iPhone5上工作,但在模拟器中工作

时间:2014-12-15 21:18:45

标签: ios ios7 swift iphone-5 swipe-gesture

我刚做了一个简单的应用程序。滑动到删除功能在模拟器(iPhone5,iOS 7.0)中运行良好,但它无法在iPhone5设备(iOS 7.0)上运行。当我滑动时,它会显示删除按钮。但是当我点击删除按钮时,没有任何反应。 这是我的代码:

func controllerWillChangeContent(controller: NSFetchedResultsController!) {
    tableView.beginUpdates()
}
func controller(controller: NSFetchedResultsController!, didChangeObject anObject: AnyObject!, atIndexPath indexPath: NSIndexPath!, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath!) {
        switch type {
        case .Insert:
            tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
        case .Delete:
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        case .Update:
            tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        default:
            tableView.reloadData()
            }
            todos = controller.fetchedObjects as [Todo]
}
func controllerDidChangeContent(controller: NSFetchedResultsController!) {
            tableView.endUpdates()
}

//RowAction: Delete
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject] {
    var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title:"Delete", handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        if let managedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext {
            let todoDelete = self.fetchResultController.objectAtIndexPath(indexPath) as Todo
            managedObjectContext.deleteObject(todoDelete)
            var e: NSError?
            if managedObjectContext.save(&e) != true{
                println("delete error: \(e!.localizedDescription)")
            }
        }
    })
    return [deleteAction]
}

0 个答案:

没有答案