【发布时间】:2009-09-24 15:06:52
【问题描述】:
大家早上好。
我在 3.1 应用程序中遇到了与表格视图有关的小问题。我有一个表格视图,其中一些复杂的 tableViewCells 从笔尖加载,它们没有被重用。感觉这可能与从笔尖加载它们有关,我决定尝试一个简单的测试项目,看看是否只使用基本的苹果模板代码来重用单元格。我从基于导航的模板开始,这里是 cellForRowAtIndexPath 的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
return cell;
}
我在下一行设置了一个断点,每次通过都会调用它。
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]
在构造函数中设置reuseIdentifier:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];
}
产生相同的结果,不重复使用单元格。
提前感谢您提供的任何帮助!
【问题讨论】:
标签: iphone uitableview iphone-sdk-3.0