0

在我的 iPad 应用程序中为 UITableView 使用带有 nib 文件的自定义扩展 UITableViewCell 时遇到问题。此单元格在选择它以将复选标记图像从选中更改为未选中时有一个行为,这取决于它是否被选中,我为此使用自定义图像,而不是 Apple 拥有的默认复选单元格。所以我的功能中的一切似乎都是正确的。我发布了一些代码。我使用 registerNib 方法来加载 nib 单元格。

[tableView registerNib: [UINib nibWithNibName: @"ANibTableViewCell" bundle: nil] forCellReuseIdentifier: Identifier];

笔尖单元使用类文件进行扩展并通过它进行管理,连接插座附加模型值等。

在 cellForRowAtIndexPath 中:

- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexpath: (NSIndexPath*) indexPath
{
ExtendedtableViewCell* cell;
AModel* model;

cell = [tableView dequeueReusableCellWithIdentifier: Identifier];
model = [modelForDisplay objectAtIndex: indexPath.row];
cell.model = model;
// Some operations setting the check mark if it needed etc.
// Checkmark is a UIImageView in the nib cell that just changes image on selection
// Some other operations happening notified by the model if selected or unselected
return(cell);
}

我的问题现在很奇怪,假设您在视觉上有 6 个单元格并且您选择了前 3 个单元格,一切都很好,但是如果您向下滚动以查看下一个单元格,假设您向下滚动 6 行,您会注意到总是每 6 个单元格3 首先看起来被选中,但是如果它被选中,我保留的扩展单元类实例未处于选中状态。这是什么视觉效果?

4

1 回答 1

0

尝试这个,

- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *Identifier = [NSString stringWithFormat:@"cell%d.%d",indexPath.section,indexPath.row];


ExtendedtableViewCell* cell;
AModel* model;

cell = [tableView dequeueReusableCellWithIdentifier: Identifier];
model = [modelForDisplay objectAtIndex: indexPath.row];
cell.model = model;
// Some operations setting the check mark if it needed etc.
// Checkmark is a UIImageView in the nib cell that just changes image on selection
// Some other operations happening notified by the model if selected or unselected
return(cell);
}

希望它会帮助你......

于 2012-10-24T12:19:27.813 回答