我制作了一个 UITableView,我正在从网络服务的 JSON 中获取数据。
Firat,我希望首先获取前 5 个对象并将它们加载到我的 tableView 中。这是正常发生的。
然后我希望每当用户滚动到页脚时..应该获取接下来的 5 个对象并将其显示在 tableView 中..
我被困在这里..任何人都可以告诉我下一步该怎么做吗?
我的表格 View 具有从不同类型的自定义类加载的所有自定义单元格?
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(section==[array count]-1)
{
UITableViewCell *cell = [self tableView:mtableview1 cellForRowAtIndexPath:myIP];
frame = cell.contentView.frame;
footerView = [[UIView alloc] init];
footerView.backgroundColor=[UIColor clearColor];
self.activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
self.activityIndicator.hidesWhenStopped=YES;
self.activityIndicator.center = CGPointMake(65,50);
[self.activityIndicator startAnimating];
UILabel* loadingLabel = [[UILabel alloc]init];
loadingLabel.font=[UIFont boldSystemFontOfSize:12.0f];
loadingLabel.textAlignment = UITextAlignmentLeft;
loadingLabel.textColor = [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0];
loadingLabel.numberOfLines = 0;
loadingLabel.text=@"Loading.......";
loadingLabel.frame=CGRectMake(95,35, 302,25);
loadingLabel.backgroundColor =[UIColor clearColor];
loadingLabel.adjustsFontSizeToFitWidth = NO;
[footerView addSubview:self.activityIndicator];
[footerView addSubview:loadingLabel];
[self performSelector:@selector(loadending) withObject:nil afterDelay:1.0];
[loadingLabel release];
NSLog(@"%f",mtableview1.contentOffset.y);
mtableview1.tableFooterView=footerView;
return footerView;
}
return nil;
}
我一直都是这样做的,但是它的位置一直都不对。这是我的大问题。
最佳答案
您可以使用以下概念。概念是当用户拉取 TableView 然后重新加载附加数据时,如拉取以刷新。
Code Sample :
//MARK: -UIScrollViewDelegate
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if (scrollView.contentOffset.y <= - 65.0f) {
// fetch extra data & reload table view
}
}
关于iphone - 如何在 UItableview 中添加带加载的页脚 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14117861/