2011-02-01 6 views
0

私は多くの人々が抱いている問題を抱えています...しかし、修正のどれも私のために働いていません。しかし、私はコードにNSLogコマンドを置くと何か不思議なことに気づいた。UITableViewの行の問題を削除します

私は、標準的な削除の方法があります。

- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath { 

    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [self.recipes removeObjectAtIndex: indexPath.row]; 
     [tableView beginUpdates]; 
     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     [tableView endUpdates]; 

    } 

} 

レシピは、データ・ソースを保持する配列です。

理論的にはこれがうまく動作するはずですが、私はエラーを取得:

invalid number of rows in section 1. The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted). 

しかし、これは私がnumberOfRowsInSectionへのNSLogを追加するとき、私はメソッドが呼び出されていることがわかり、バラバラにされた場合、私は知っています上記の方法から2回。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    NSLog(@"THIS CALLED TWICE %i",[recipes count]); 
    return [recipes count]; 
} 

他に、numberOfRowsInSectionメソッドが2回発生する可能性があるのは誰ですか?

ありがとうございます。

+0

タグ 'xcode'が削除されました。 – vikingosegundo

答えて

0

これを書いた後、私は次のことをしていたことを見た:にどうやら、numberOfRowsInSectionは、セクションごとに呼び出され

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 2; 
} 

...コードを変更:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
     // Return the number of sections. 
     return 1; 
    } 

は、問題を修正しました。

+0

あなたの答えをチェックしてください! – Sarah

関連する問題