5

iOS6 とストーリーボードを使用して、3 つのセクションを持つ UITableViewController を作成しました。

最初の 2 つのセクションは静的で、3 番目は動的です。

をオーバーライドnumberOfRowsInSectionし、セクション 0cellForRowAtIndexPathheightForRowAtIndexPath1 については super を適切に延期し、セクション 2 についてはデータ モデルから適切な値を返すようにしました。

それでも、データの行数が 3 番目のセクションのストーリーボードで構成された行数を超えると、main() で NSRangeException が発生します。

'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: (0x22f3012 0x178ae7e 0x22a8b44 0xb0ece4 0x8feee3 0x784f13 0x71940c 0x784a7b 0x789919 0x7899cf 0x7721bb 0x782b4b 0x71f2dd 0x179e6b0 0x558fc0 0x54d33c 0x54d150 0x4cb0bc 0x4cc227 0x4cc8e2 0x22bbafe 0x22bba3d 0x22997c2 0x2298f44 0x2298e1b 0x26867e3 0x2686668 0x6ceffc 0x2c4d 0x2b75) libc++abi.dylib: terminate called throwing an exception

この例外が発生しないようにするには、どのスーパークラス メソッドをオーバーライドする必要がありますか?

4

1 に答える 1

11

私が欠けていた実装は次のとおりです。

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { return 0; }

これは、動的動作を静的プロトタイプ UITableViewController に挿入するためにオーバーライドする必要がある合計 4 つのメソッドがあることを意味します。

  1. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

  2. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

  3. -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

  4. -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

これが誰かの時間を節約することを願っています。

于 2013-04-17T14:59:51.687 に答える