不允许选择时如何避免点击 table 视图单元格中的附件按钮?
How to avoid tap on accessory button in table view cell when selection is not allowed?
我的 table 视图显示包含一些内容和自定义附件按钮的单元格。
当我点击一个单元格时,会启动一个 5 秒的作品。我不希望用户在后台工作未完成时点击单元格,所以我这样做:
self.tableView.allowsSelection = NO;
它工作正常,用户不能点击单元格。
我曾经做过:
self.tableView.userInteractionEnabled = NO;
但我想在后台工作时滚动 table 视图。问题是我也可以点击手机的附件按钮。
如何避免不丢失 table 视图滚动条?
我能做到:
- (void)didSelectAccessoryButton:(UIButton *)pButton onEvent:(id)event{
if(self.tableView.allowsSelection){
//Usual accessory button code
}
}
但是附件按钮高亮显示仍然存在,这意味着在某些时候我需要在 cellForRowAtIndexPath
:
[accessoryButton setShowsTouchWhenHighlighted:NO];
我只希望 allowsSelection = NO
也能避免点击附件按钮...那么更好的方法是什么?
我发现的最好方法是结合这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//...
tableView.allowsSelection = NO;
[tableView reloadData];
//...
}
有了这个:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//...
accessoryButton.userInteractionEnabled = tableView.allowsSelection;
//or cell.accessoryView.userInteractionEnabled = tableView.allowsSelection;
//
}
工作完成后,self.tableView.allowsSelection = YES;
。
这个解决方案困扰我的是需要检查内部 cellForRowAtIndexPath
为此我还需要重新加载数据;但最后只有 3 行。
感谢@virus 的简单 "userInteractionEnabled to accessoryButton" 想法。
我的 table 视图显示包含一些内容和自定义附件按钮的单元格。
当我点击一个单元格时,会启动一个 5 秒的作品。我不希望用户在后台工作未完成时点击单元格,所以我这样做:
self.tableView.allowsSelection = NO;
它工作正常,用户不能点击单元格。
我曾经做过:
self.tableView.userInteractionEnabled = NO;
但我想在后台工作时滚动 table 视图。问题是我也可以点击手机的附件按钮。
如何避免不丢失 table 视图滚动条?
我能做到:
- (void)didSelectAccessoryButton:(UIButton *)pButton onEvent:(id)event{
if(self.tableView.allowsSelection){
//Usual accessory button code
}
}
但是附件按钮高亮显示仍然存在,这意味着在某些时候我需要在 cellForRowAtIndexPath
:
[accessoryButton setShowsTouchWhenHighlighted:NO];
我只希望 allowsSelection = NO
也能避免点击附件按钮...那么更好的方法是什么?
我发现的最好方法是结合这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//...
tableView.allowsSelection = NO;
[tableView reloadData];
//...
}
有了这个:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//...
accessoryButton.userInteractionEnabled = tableView.allowsSelection;
//or cell.accessoryView.userInteractionEnabled = tableView.allowsSelection;
//
}
工作完成后,self.tableView.allowsSelection = YES;
。
这个解决方案困扰我的是需要检查内部 cellForRowAtIndexPath
为此我还需要重新加载数据;但最后只有 3 行。
感谢@virus 的简单 "userInteractionEnabled to accessoryButton" 想法。