2011-09-05 49 views
0

我使用MWFeedParser库来解析xml。 当我将numberOfRowsInSection更改为+1(返回[itemsToDisplay count] +1;) 为Load more选项创建最后一个单元格行时,我的应用程序在此行中崩溃: MWFeedItem * item = [itemsToDisplay objectAtIndex:indexPath.row ]。加载更多单元格问题

任何想法为什么发生这种情况?

回答

0

欢迎您试图从数组中获取超出该数组中项目数的项目。 (也接受一些雁,人们更愿意,如果你接受的答案雁)

例如: 你做的numberOfRowsInSection加1其作为实例,返回11 这意味着,还有在10项itemsToDisplay数组。 您正在使用MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row]检索itemsToDisplay中的项目,但您不能检索项目编号11,因为它不存在。

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

if (indexPath.row < [itemsToDisplay count]) { 
    MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row]; 
    // Set the cell here 
} else { 
    //create a cell with the text "Load More" 
} 
+0

TNX的快速回答:)现在我知道这个问题,但如何解决呢? – user535351

+0

和BTW我如何接受答案? – user535351

+0

查看常见问题解答:http://stackoverflow.com/faq#howtoask – rckoenes