2017-08-08 15 views
0

ユーザーが完全/不完全のようにUITableViewRowActionのタイトルを変更するたびに、私が書いたコードはチェックマークを入れますが、タイトルは変更しないので、チェックマークは変更できません削除する:UITableViewRowAction swiftのタイトルを変更する3

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let completeAction = UITableViewRowAction(style: .normal, title: "Complete", handler: { (action, indexPath) in 
     if action.title == "Complete"{ 
      action.title = "Incomplete" 
      cell?.accessoryType = UITableViewCellAccessoryType.checkmark 
     } 
     else{ 
      cell?.accessoryType = UITableViewCellAccessoryType.none 
      action.title = "Complete" 
     } 
     tableView.setEditing(false, animated: true) 
    }) 
    completeAction.backgroundColor = .blue 
    return [completeAction] 
} 

アドバイスはありますか?

答えて

0

これは、私はそれを解決する方法である:

var complete:Bool = false 
{ 
    didSet{ 
     if complete { 
      comp = "Incomplete" 
     } 
     else{ 
      comp = "Complete" 
     } 
    } 
} 
var comp:String = "Complete" 

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let cell = tableView.cellForRow(at: indexPath) 
    let completeAction = UITableViewRowAction(style: .normal, title: "\(comp)", handler: { (action, indexPath) in 
     if action.title == "Complete"{ 
      self.complete = true 
      cell?.accessoryType = UITableViewCellAccessoryType.checkmark 
     } 
     else{ 
      self.complete = false 
      cell?.accessoryType = UITableViewCellAccessoryType.none 
     } 
     tableView.setEditing(false, animated: true) 
    }) 
    completeAction.backgroundColor = .blue 
    return [completeAction] 
} 
関連する問題