UITableView
当用户滚动到 tableView 的底部时,我正在尝试向 a 添加 10 多条记录。我正在使用scrollViewDidEndDecelerating
: 然后 a-(void)getFeed:
获取数据并将其存储在一个NSMutableArray
被调用的moreitems
. moreitems
然后应该self.listingNodesArray
与表中已经存在的记录一起附加到表的底部,然后再附加到表的底部。
我认为我的问题在于insertRowsAtIndexPaths:
方法。我不知道在那之后放什么。目前应用程序崩溃[self.tableView endUpdates];
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidEndDecelerating");
float endScrolling = scrollView.contentOffset.y + scrollView.frame.size.height;
if (endScrolling >= scrollView.contentSize.height)
{
index ++;
[self getFeed:index];
}
}
- (void)getFeed:(NSInteger) pageNumber
{
NSError *requestError = nil;
NSString *savedValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"token"];
NSLog(@"countpage %d",index);
NSString *stringWithToken = [NSString stringWithFormat:@"%@&%@&page=%d&token=%@",kURL,city_slug, pageNumber, savedValue];
NSLog(@"string token is %@", stringWithToken);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:stringWithToken]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&requestError];
NSError *jsonParsingError = nil;
if (requestError) {
NSLog(@"sync. request failed with error: %@", requestError);
}
else {
// handle data
NSDictionary *publicData = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
moreItems = [publicData objectForKey:@"data"];
}
NSLog(@"moreitems data output is %@",moreItems);
[self.listingNodesArray addObjectsFromArray:moreItems];
int newRowIndex = [self.listingNodesArray count];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex+1 inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];
NSLog(@"updated self.listingNodesArray %@ and count is %d",self.listingNodesArray, [self.listingNodesArray count]);
}
感谢您对此的任何帮助。