UITableView在第一次加载时不响应滚动 [英] UITableView does not respond to scrolling the first time it's loaded

查看:52
本文介绍了UITableView在第一次加载时不响应滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,第一次加载UITableView时,它不会对滚动触摸做出响应-如果它的行数不超过屏幕显示的容量.如果我关闭视图,则重新打开相同的对象-现在它会响应触摸-即使它包含相同数量的行.

I have found that the first time a UITableView loads, it does not respond to scrolling touches -- if it does not have more rows than fit on the screen. If I close the view, then reopen the same object -- it will now respond to touches -- even though it contains the same number of rows.

除了对行数响应UITableViewDataSource方法并自行生成行外,我没有做任何其他事情.每当视图出现时,我都会重新加载表.

I am not doing anything more than responding to the UITableViewDataSource methods for the number of rows, and generating the rows themselves. I am reloading the table every time the view appears.

任何人都可以解释这种行为吗?

Can anyone explain such behavior?

我正在像这样创建单元格:

I am creating the cells like so:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *tableId = @"NewIndexTableId";
  Note *note = [notes objectAtIndex:[indexPath row]];

  UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:tableId];

  if (cell == nil)
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableId] autorelease];

  cell.textLabel.text = note.text;
  cell.detailTextLabel.text = [note changedDelta]; 
  cell.accessoryView = multipleAccounts ? [note.account imageView] : nil;

  return cell;  
}

推荐答案

我解决了此问题,方法是确保表中始终至少有10行-当实际行数少于10时创建虚拟行.这解决了故障.

I solved this problem by making sure there are always at least 10 rows in the table -- creating dummy rows when there are less than 10 real rows. This solved the glitch.

这篇关于UITableView在第一次加载时不响应滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆