2016-07-02 10 views
0

私は方法テーブルビューのメソッドfunc tableView(tableView:UITableView、editActionsForRowAtIndexPath indexPath:NSIndexPath)の問題 - > [UITableViewRowAction]?

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? 
{ 
let delete = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in 
     //Do something 
    }) 
    delete.backgroundColor = UIColor.redColor() 

    let more = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in 
     //Do something 
    }) 
    more.backgroundColor = UIColor.blueColor() 

    return [delete, more] 
} 

を使用しています私はまた

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    // you need to implement this method too or you can't swipe to display the actions 
     } 

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // the cells you would like the actions to appear needs to be editable 
    return true 
} 

を含めて、私は私が表示されない作成し、右または左のボタンをスワイプするとき。私はeditactionforrowatindexpathにオーバーライドを入れようとしましたが、メソッドがスーパークラスのメソッドをオーバーライドしないというエラーが発生しました

+0

をドラッグすることで、デリゲートとデータソースメソッドを接続する必要があるが、ブレークポイントを入れて、機能が 呼び出されたりされていないことを確認しますか?あなたの代理人が正しく設定されているかどうかチェックしてください! – Pushp

+0

私はuitableviewdelegateとuitabledatasourceを使用していますが、その機能が呼び出されていないのはわかりませんなぜ@Pushp –

+0

あなたはすでに設定していますか?そうであれば ?それからどう? programeticallyまたはstoryboadrdを使用して? – Pushp

答えて

1

実装に間違いはありません。デリゲートメソッドとデータソースメソッドが正しく呼び出されないため、この関数は呼び出されません。

デリゲートメソッドとデータソースメソッドは、プログラムでもストーリーボード経由でも接続できます。

プログラムでテーブルビューを実装する場合UITableViewDataSource、UITableViewDelegateをクラス宣言に追加し、このコードを使用してデリゲートを接続する必要があります。

  yourTableView.datasource = self 
      yourTableView.delegate = self 

あなたはストーリーボードを通じてテーブルビューを実装している場合は、あなただけの

Connect delegate and datasource methods via storyboard

+0

私はあなたが言ったことをしましたが、それはまだ呼び出されていません –

+0

私はそれをプログラムで行いました –

+0

あなたはtableviewを使用しているクラスを共有できますか? –

関連する問題