【发布时间】:2015-07-09 16:28:56
【问题描述】:
我有 UITableView 标题自定义,如 Instagram,我的部分充当标题,在这个 tableview 中,我还使用分页从服务器获取数据。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (currentPage == 0) {
return 1;
}
if (currentPage < totalPages) {
return myObject.count+1;
}
return myObject.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 1;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection (NSInteger)section
{
myTimeline = [myObject objectAtIndex:section];
//the rest of my code to display text in UILabel cell, etc
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell.tag == kLoadingCellTag) {
currentPage++;
[self getTimeline];
}
}
现在的问题是,我已经确保我的分页工作正常并且 myObject 数组计数增加了。 但是当我进行滚动时,它在方法 viewForHeaderInSection 中崩溃,原因是“索引 10 超出范围 [0 .. 9]'”(我在服务器中设置了分页,每页 10 个项目)
我认为 ViewForHeaderInSection 中的部分没有使用我已经设置的 numberOfSectionsInTableView 方法进行更新。
那么如何更新 ViewForHeaderInSection 中的部分呢?
谢谢..
【问题讨论】:
-
“我在服务器中设置了每页 10 个项目的分页” - 你的服务器是否总是有 10*k 个条目?
标签: ios objective-c uitableview