2017-11-13 14 views
1

UIContextualActionの実行中と実行後にUITableViewCellのテキストを取り消すにはどうすればよいですか?途中で途切れたUITableViewCellテキストフィールド "完了"

Strikethrough example

func tableView(_ tableView: UITableView, 
       leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? 
{ 
    let doneAction = UIContextualAction(style: .normal, title: "DONE", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in 
     print("Done left") 

     self.dailyTasks.append("\(self.dailyTasks[indexPath.row])") 
     self.dailyTasks.remove(at: indexPath.row) 

     UserDefaults.standard.set(self.dailyTasks, forKey: "dailyTasks") 

     self.dailyTable.reloadData() 

     success(true) 

    }) 
    doneAction.backgroundColor = .darkGray 

    return UISwipeActionsConfiguration(actions: [doneAction]) 

} 

答えて

0

あなたはattributedtextとしてラベルテキストが表示されます(それが中に行うことができない場合は、後にのみ、参考になります)。このコードを試してください。 getRespectiveCellメソッドは実装されていません。そのindexpathのために、それぞれのセルを取得するために、独自のロジックを入れ

let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "Your Text") 
    attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length)) 

let cell = getRespectiveCell(indexPath.row) 
cell.textLabel.attributedText = attributeString 
+1

@ahmedありがとうございました。私は次のようにそれぞれのセルを得ることができました: let cell = self.dailyTable.dequeueReusableCell(withIdentifier: "Cell"、for:indexPath) – reinho14

関連する問題