dhr*_*hrm 2 cocoa-touch objective-c uitableview ios
我有一个UITableView,其中数据源是使用NSFetchRequest的 Core Data .核心数据包含从我的网站上的数据库下载的新闻项目.默认情况下,核心数据包含50个最新项目,当达到UITableView的底部时,旧项目是延迟下载的.
我正在使用这个tableView:numberOfRowsInSection方法处理这个问题,我在最后一节返回+1,这是我的"加载项目"单元格.在tableView:cellForRowAtIndexPath方法中,当IndexPath是最后一节中的最后一行时,我正在创建"正在加载项"单元格.
问题在于,当下载新数据时,之前是"加载项目"单元格的单元格现在是常规新闻项目单元格.但是当我从细胞中滚动并返回时,首先重新加载细胞.
我可以存储"装载项"单元格的indexPath,并在延迟加载完成后重新加载该单元格.但我想知道,如果存在更好的解决方案吗?
EDIT1:
这是我创建"加载项目"UITableViewCell的过程.
cell.textLabel.text = [NSString stringWithFormat:@"%@\u2026", NSLocalizedString(@"LOADING_MORE", nil)];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIImage *spacer = [UIImage imageNamed:@"Spacer"];
UIGraphicsBeginImageContext(spinner.frame.size);
[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = resizedSpacer;
[cell.imageView addSubview:spinner];
[spinner startAnimating];
Run Code Online (Sandbox Code Playgroud)
EDIT2:
我正在尝试使用下面的代码"设计"footerView.目前,活动指示器位于左上角位置,标签不可见.
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
NSInteger sectionsAmount = [tableView numberOfSections];
if (section == sectionsAmount - 1) {
return 20;
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
NSInteger sectionsAmount = [tableView numberOfSections];
if (section == sectionsAmount - 1) {
if (_tableFooterView==nil) {
UIView *view = [[UIView alloc] init];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIImage *spacer = [UIImage imageNamed:@"Spacer"];
UIGraphicsBeginImageContext(spinner.frame.size);
[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = resizedSpacer;
[imageView addSubview:spinner];
[spinner startAnimating];
[view addSubview:imageView];
UILabel *label = [[UILabel alloc] init];
label.text = [NSString stringWithFormat:@"%@\u2026", NSLocalizedString(@"LOADING_MORE", nil)];
[view addSubview:label];
_tableFooterView = view;
}
return self.tableFooterView;
}
return nil;
}
Run Code Online (Sandbox Code Playgroud)
如何将UIView更改为如下图所示:

EDIT3:
这是我的setupTableFooterView,我正在为其分配视图tableFooterView.从viewDidLoad调用该方法.
- (void) setupTableFooterView {
UIView *view = [[UIView alloc] init];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIImage *spacer = [UIImage imageNamed:@"Spacer"];
UIGraphicsBeginImageContext(spinner.frame.size);
[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = resizedSpacer;
[imageView addSubview:spinner];
[spinner startAnimating];
imageView.frame = CGRectMake(10, 11, 20, 20);
[view addSubview:imageView];
UILabel *label = [[UILabel alloc] init];
label.text = [NSString stringWithFormat:@"%@\u2026", NSLocalizedString(@"LOADING_MORE", nil)];
[label setFont:[UIFont italicSystemFontOfSize:13]];
[label setFrame:CGRectMake(40, 0, 270, 43)];
[view addSubview:label];
self.tableView.tableFooterView = view;
}
Run Code Online (Sandbox Code Playgroud)
使用UITableView tableFooterView替代该消息.这样你就不必弄乱部分/行结构了.
tableFooterView
Run Code Online (Sandbox Code Playgroud)
返回显示在表格下方的附件视图.
@property(nonatomic, retain) UIView *tableFooterView
Run Code Online (Sandbox Code Playgroud)
讨论
默认值为nil.表格页脚视图与章节页脚不同.
| 归档时间: |
|
| 查看次数: |
2845 次 |
| 最近记录: |