【问题标题】:UITableViewCell strange behavior when on select changing an image insideUITableViewCell 选择更改内部图像时的奇怪行为
【发布时间】:2012-10-24 11:52:07
【问题描述】:

在我的 iPad 应用程序中使用带有 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 个首先看起来被选中,但是如果它被选中,我保留的扩展单元格类实例未处于选中状态。那是什么视觉效果?

【问题讨论】:

  • 如果我正确理解您的问题,问题是:考虑您选择了前 3 个单元格,其余 3 个单元格处于未选中状态。然后向下滚动以查看第 6 个单元格,因为您的表格框架小到只能容纳 3 个可见行。当你回来看到前 3 个选定的单元格时,它再次取消选择或其他什么?
  • 不,你向下滚动,第 7、8、9 个单元格被选中是有原因的,第 10、11、12 个单元格没有被选中,并且所有记录都这样持续下去 + 那些已经被选中所以发生了混乱。

标签: objective-c ipad ios5 uitableview


【解决方案1】:

试试这个,

- (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);
}

希望对你有所帮助.....

【讨论】:

  • 这会使应用程序崩溃,我猜你忘记了我使用 registerNib UITableView 方法注册 nib 文件。也许如果我在扩展类中加载笔尖来加载?
猜你喜欢
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 2014-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多