2011-06-24 6 views
0

insertRowsAtIndexPathsを使用しようとしているので、テーブル行を挿入できます。私はこのエラーを取得しています:私が何をしようとしています何UITableViewの行数を動的に変更しようとするとNSInternalInconsistencyExceptionが発生する

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',  reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).' 

は動的問題を整流で私の試みで、セクション内の行数を変更することです:

NSArray *indexPathIndex = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil];  
[myTableView beginUpdates]; 
//***** HERE I AM TRYING TO DYNAMICALLY INCREASE NUMBER OF ROWS 
[myTableView numberOfRowsInSection:1]; 
//////////////////////////////////////////////////////////// 
[myTableView insertRowsAtIndexPaths:indexPathIndex withRowAnimation:UITableViewRowAnimationTop]; 
[myTableView endUpdates]; 

最初に、行の私の電話番号を上記のエラーに対処するために私はこの数を増やそうとしますが、コード[myTableView numberOfRowsInSection:1]は何の効果もないようです。

誰かがこの問題をどのように解決できるかお勧めしますか?

ありがとう、 ビクター。

+2

あなたは – crashmstr

答えて

0

自分で行数を設定しないでください.UITableViewはそれを独自に管理します。行を削除します。

myTableView numberOfRowsInSection:1]; 
+0

こんにちは、あなたのタイトルは、より説明的にする必要があります。私はあなたがアドバイスした通りにこの行を削除しましたが、問題を解決する他の方法はわかりません "更新(0)後の既存のセクションに含まれる行の数は、そのセクションに含まれる行の数更新(0)、そのセクション(挿入された1、削除された0)から挿入または削除された行の数をプラスまたはマイナスします。 - このエラーメッセージが私に求めている行の数を変更するには、何らかの方法が必要です。 – victor2010

0

UITableViewDataSourceプロトコル、特にtableView:numberOfRowsInSection方法を見てみましょう。これにより、セクション内の行数を動的に設定することができます。

0

tableViewには、一般に配列であり、tableViewのセルを塗りつぶすために使用できるデータソースがあります。あなたが動的にtableViewの内容を変更したい場合は

- (UITableViewCell*)tableView cellForRowAtIndexPath..... { 
    //Dequeueing or alloc-init-ing a cell 
    SomeClass *someObject = [someArray objectAtIndex:indexPath.row]; // Something 
    // like this, where someArray becomes the source array. 
    ... 
} 

は今、あなたのコードのいくつかの他の部分では、someArrayを変更してからのtableViewを変更します。

[someArray insertObjectAtIndex:someIndex]; 
[myTableView insertRowsAtIndexPaths....]; //The indexPath is generally 
// consistent with the someIndex. 
+0

皆さん。あなたの返事をありがとうございました。 UIViewControllerの代わりにUITableViewControllerをサブクラス化する新しいクラスを作成することで実装を変更し、その後はすべて正常に機能しました。なぜそれがUIViewControllerクラスでうまくいかなかったのか分かりません。ご協力いただきありがとうございます。 – victor2010

関連する問題