4

我想禁用单元格交互。在我的功能中:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

我添加了

Cell.userInteractionEnabled = NO;

并且单元格交互被禁用,但我想保留活动按钮(ButtonLabel)。

Cell.userInteractionEnabled = NO;
Cell.ButtonLabel.userInteractionEnabled = YES;

上面的代码不起作用。这很奇怪,因为 inversly 是可以的:

Cell.userInteractionEnabled = YES;
Cell.ButtonLabel.userInteractionEnabled = NO;

按钮被禁用,但单元格没有。

如何在单元格被禁用时使我的按钮处于活动状态?

4

3 回答 3

3

当您在 UIView (或其子类)的任何实例上设置userInteractionEnabled为时NO,它会自动禁用其所有子视图上的用户交互。这正是您描述的行为。

我认为您想要做的是禁用 UITableViewCell 上的选择。有几种方法可以做到:

  1. 如果您想完全阻止选择所有单元格,您可以设置tableView.allowsSelectionNO.
  2. 如果您只想阻止在某些单元格上进行选择,请执行Cell.selectionStyle = UITableViewCellSelectionStyleNone;

您还可以覆盖- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;并返回nil不应触发选择操作的单元格(但这本身不会阻止选择突出显示的出现。)

于 2013-10-24T08:58:15.533 回答
1

根据您的评论,您希望禁用特定单元格的推送连接。您可以做的是检查 shoudlPerformSegueWithIdentifier 是否应该执行该单元格。

您需要保存哪个单元格被触摸,然后:

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    if (/*check if the selected cell should perform the segue*/) {
        return YES;
    }

    return NO;
}
于 2013-10-24T09:34:47.597 回答
1

如果您禁用单元格上的交互,这将影响所有单元格元素。您想要做的是将单元格设置为UITableViewCellSelectionStyleNone

这将起作用

 [Cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Cell.ButtonLabel.userInteractionEnabled = YES;
于 2013-10-24T08:53:33.903 回答