2011-01-02 7 views
0

私のUITableViewはUIViewControllerインスタンスにリンクされています。 UIViewControllerインスタンスは、テーブルのUITableViewDelegateおよびUITableViewDataSourceです。UITableViewは「スワイプして削除」モードには入りません

セルがシミュレータでスワイプされると、「スワイプから削除」モードが起動されません。 "スワイプの削除"と表のセル編集をサポートするメソッドの実装を提供しようとしました。いずれも呼び出されません(NSLogのどれもロギングされません)。

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"tableView editingStyleForRowAtIndexPath"); 
    return UITableViewCellEditingStyleDelete; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"tableView canEditRowAt..."); 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"tableView willBeginEditingRowAtIndexPath: %@", indexPath); 
} 

- (void)tableView:(UITableView *)tableView willEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"tableView willEndEditingRowAtIndexPath: %@", indexPath); 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle { 
    NSLog(@"tableView commitEditingStyle"); 
} 

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"tableView didEndEditingRowAtIndexPath"); 
} 

私は忘れていますが、何が分からないのでしょうか。何か案は?

答えて

2

tableView:commitEditingStyle:を実装しましたが、必要な方法はtableView:commitEditingStyle:forRowAtIndexPath:です。

これはプロトコルを実装する際の課題の1つです。オプションのメソッドを間違って指定したり、間違って入力した場合、コンパイラが知る方法はありません。

ヒント1:カット&ペーストプロトコルメソッド宣言を直接ドキュメントからスペルミスを回避し、引数を逃した。ここ

は、将来的に役立つかもしれないいくつかのヒントです。

ヒント2:(ほとんどが空のボディで)正しいプロトコルメソッドのセットを作成し、コードスニペットライブラリに配置します。次に、プロトコルを採用するときは、常にスニペットを使用してください。

+0

ありがとうございました! – byneri

関連する問題