2016-03-30 9 views
0

私は私のアプリでUITableViewControllerを実装していると私はまさにこの答えのように、私のテーブルビューのセルをスワイプ/スライドの可能性を追加したい:すべてではなく、Swipe-able Table View Cell in iOS 9それは1つの特定のセルのために働く差そのうちの。Swiftの特定のUITableViewCellに対してのみeditActionsForRowAtIndexPathを実装する方法はありますか?

class MyTableViewController: UITableViewController { 



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

override func tableView(tableView: (UITableView!), commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: (NSIndexPath!)) { 

} 

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

    var deleteAction = UITableViewRowAction(style: .Default, title: "Hello There!") {action in 
     print("some action!!") 
    } 

    return [deleteAction] 
} 

} 

をし、それがすべてのセルのスワイプを追加し、私は私のリスト上の第3回1(細胞が動的に生成されていない)に追加したい:これまでのところ私が持っています。それをする方法はありますか?

答えて

2

あなたは、パラメータとして与えられているセルのindexPathをチェックし、それに基づいて適切な応答を返すことができます。さらに、セルが異なる場合は、func cellForRowAtIndexPath(_ indexPath: NSIndexPath) -> UITableViewCell?を使用してセルのタイプを確認することもできます。

インデックスパスはクラスです。 indexPath.rowを使用して、indexPathから現在の行のインデックスを取得できます。

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    if ((indexPath.row % 3) == 0) { 
     return true 
    } else { 
     return false 
    } 
} 
+0

ですが、数値3と比較できるintの 'indexPath'ですか?この場合、どのくらい正確にそれを行うことができますか? – randomuser1

+1

[OK]を3 – dan

+0

に 'indexPath.row'を比較することができますので、私はやった:'場合(indexPath.row == 2){VARのdeleteAction = UITableViewRowAction(...}他{戻りはnil} 'が、まだそれがスライドすることが可能ですすべてのセル。その解決策と私の3番目のセルに、私は 'こんにちはあり、文字列を参照してください!'と私は、文字列 'DELETE'を参照してください他のものをスライドさせます。完全に、他の細胞をスライドさせる可能性を除去する方法はありますか? :) – randomuser1

関連する問題