文本字段独立的UITableViewCell

问题描述

我在表视图单元格中有一个文本框和两个按钮,当您单击该文本框时,它会打开一个pickerview进行选择。我想要的是,用户应该只能单击文本字段和按钮,而不能单击tableviewcell。我不希望该单元格是可选的,而是仅文本字段和按钮是可选的,我该怎么做?

我已经尝试过cell.selectionType和cell.userinteractionenabled,但是它们只是使整个单元格都无法选择,即使其中的文本字段也是如此……这不是我想要的。

screenshot of what tableviewcell looks like

请帮助! 谢谢!

解决方法

cellForRowAtIndexPath中:

if (indexPath.section == 0) {
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}

然后还实现willSelectRowAtIndexPath

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return nil;
    }
    return  indexPath;
}