【发布时间】:2013-05-02 02:04:42
【问题描述】:
再次出现 Utableview 问题。每当我重新加载数据时,表格视图都会重新加载,但数据似乎不会从第一行开始。请参考下图。
我在重新加载数据后尝试了以下方法,但仍然没有成功:
[self.tableView reloadData];
// this or the other one ... [self.tableView setContentOffset:CGPointZero animated:NO];
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
这就是我在 viewdidload 上定位 uitableview 的方式
self.tableView.frame = CGRectMake(450, 20, self.tableView.frame.size.width, self.tableView.frame.size.height - 20);
编辑 1:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SearchResultCell";
User *user = [users objectAtIndex:indexPath.row];
UserTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UserTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.name.text = [NSString stringWithFormat:@"%@ %@", user.firstName, user.lastName];
return cell;
}
【问题讨论】:
-
cellForRowAtIndexPath: 是什么样子的?
-
用 cellForRow 更新
-
啊,我的错,误读了问题。
-
我建议滚动到 0,0 然后重新加载 - 除非您有特定的理由不这样做。此外,由于您正在处理 UIScrollView 子类,您只需将 contentOffset 设置为 CGPointZero。
标签: cocoa-touch uitableview reloaddata