2016-12-03 38 views
0

我有一個如何根據IndexPath.row設置自定義的UITableViewRowAction?

  • 的tableView(UITableView的)
  • customCell:UITableViewCell的!
  • itemsArray:[項目]

我試圖在UITableView中視IndexPath.row設置自定義操作單元。

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) 
-> [UITableViewRowAction]? { 

    if !(itemsArray[indexPath.row].isReadOnly) { 

    let editAction = UITableViewRowAction(style: .normal, title: "Edit") { 
     (tableViewRowAction, indexPath) in 
     print("Edit Item \(self.itemsArray[indexPath.row].caption)\n") 
    }  
    return [editAction] 
    } else { 
    return [] 
    } 
} 

我試圖在UITableView中視IndexPath.row設置自定義操作單元:與細胞,我想是沒有動作(對應項目具有.isReadOnly =真發生

問題)

我試圖回零,在其他情況下與這兩個變種[]具有刷卡無關的結果: - 零 - 刪除動作顯示項目 - [] - 細胞揮筆一點點,「unswipes」回比揮動停止工作任何細胞

回答

0

我找到了解決方案:只是使用的UITableView

的canEditRowAt方法
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    return !(items[indexPath.row].isReadOnly) 
}