2013-04-17 52 views
5

使用iOS6和故事板,我有一個包含3個部分的UITableViewController。帶有混合靜態/動態內容的UITableViewController中的NSRangeException

前兩部分是靜態的,第三部分是動態的。

我已經覆蓋numberOfRowsInSectioncellForRowAtIndexPathheightForRowAtIndexPath適當推遲到超級的部分0和1,並從我的數據模型爲第2

還是回到合適的值,我得到了一個主要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

哪個超方法我必須覆蓋,以防止此異常的發生?

回答

11

我失蹤的實施是:

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

這意味着總共有四種方法之一必須覆蓋注入動態行爲爲靜態原型的UITableViewController是:

  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

希望這樣可以節省別人一些時間。

+0

神聖的廢話你是對的。我從來不會猜測。過去24小時有同樣的問題,並把我的頭髮撕掉。謝謝!!!!!!!!!! – nurider