【问题标题】:How do I unhighlight an accessory in a UITableView after the row is deselected?取消选择该行后,如何取消突出显示 UITableView 中的附件?
【发布时间】:2013-03-14 16:28:06
【问题描述】:

我有一个带有自定义附件按钮的 UITableView。选择表单元格后,将附件按钮放置在突出显示的状态下。好吧,这是一件好事。当另一个单元格被选中,导致第一个取消选择时,附件按钮不会变回未突出显示的状态。

这是一个屏幕截图,显示了一个不再被选中的单元格(Rose),但仍然选择了辅助按钮。

我已经尝试过这里建议的解决方案。 AccessoryDetailDisclosureButton not deselecting after I call deselectRowAtIndexPath 不行。我重新加载了表格中的每个单元格,但它仍然没有将附件按钮置于未突出显示的状态。

我尝试在新选择的按钮的选择器和tableView:accessoryButtonTappedForRowWithIndexPath: 方法中显式取消突出显示单元格中的按钮。不开心。

这是创建按钮的代码:

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
...
    UIButton *folderButton = [UIButton buttonWithType: UIButtonTypeCustom];
    folderButton.frame = CGRectMake(0.0, 0.0, 33.0, 33.0);
    [folderButton setImage: [UIImage imageNamed: @"open_document.png"] forState: UIControlStateNormal];
    [folderButton addTarget: self action: @selector(documentButtonAction:) forControlEvents: UIControlEventTouchUpInside];
    [folderButton setTag: [program tag]];
    cell.accessoryView = folderButton;

...
}

到目前为止,我发现的唯一解决方案是将突出显示的按钮图像设置为未突出显示的图像,但这也很糟糕,因为点击时按钮不会突出显示。

如何取消突出显示附件按钮?

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    试试这个...

    [tableView reloadRowsAtIndexPaths:@[indexPathToDeselect]
                     withRowAnimation:UITableViewRowAnimationNone];
    

    其中indexPathToDeselect 是之前突出显示的行的索引路径。这将强制重绘该行。

    【讨论】:

    • 正如帖子中提到的,我确实尝试过这种方法。它没有用。
    • 奇怪的是,我尝试重新加载整个表而不是行,并且 确实 工作。诡异的。 [self.programTableView reloadData];
    【解决方案2】:

    您可以尝试使用委托方法tableView:willDeselectRowAtIndexPath:tableView:didDeselectRowAtIndexPath: 并在此处取消选择您的自定义附件视图。

    【讨论】:

    • 见上文。我确实试过这个;那没起效。桌子上一定还有其他奇怪的东西。无论如何,当我重新加载 整个 表时,而不仅仅是行,它起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    相关资源
    最近更新 更多