2015-09-03 3 views
0

У меня есть UITableview. Все работает, за исключением прокрутки влево, чтобы показать кнопку «Удалить». Похоже, что didSelectRowAtIndexPath выполнен до canEditRowAtIndexPath. Как изменить, чтобы заставить его остановиться и показать кнопку удаления вместо того, чтобы показывать новый UIView?didSelectRowAtIndexPath выполняется до canEditRowAtIndexPath

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    println("Edit") 
    return true 
} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    println("Select") 
    println(indexPath.row) 


    let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("CklDtljChnge") as! UIViewController 

    self.presentViewController(viewController, animated: false, completion: nil) 

} 

ответ

0

Для этого вам необходимо добавить эти методы делегата.

func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle { 


     return UITableViewCellEditingStyle.Delete 

    } 
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
     if (editingStyle == UITableViewCellEditingStyle.Delete) { 

      // do your stuff. 

     } 
    } 
Смежные вопросы