我发现,第一次加载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在第一次加载时不响应滚动
发布评论