use*_*439 10 button uitableview clickable ios
我有一些带有一些单元格的tableView.每个单元格还包含一个按钮.当用户单击按钮时,单元格应该是不可点击的,而不是按钮.因此,当用户单击不可单击的单元格的按钮时,此单元格应再次可单击.
我试过了:
cell.userInteractionEnabled = NO;
Run Code Online (Sandbox Code Playgroud)
...但是按钮不再可点击了.
感谢您提前付出的努力.
编辑 我的意思是:当我点击一个单元格时,会打开一个新视图.但我希望,当细胞不是"可点击的"时,不会发生任何动作.
Luc*_*rdo 16
不可点击的方式?如果您只想让单元格无法选择,那么您可能正在寻求:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)
如果要在禁用选择时阻止执行代码,只需检查方法中的选择属性didSelectRowAtIndexPath:.像这样的东西:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.selectionStyle != UITableViewCellSelectionStyleNone) {
//(your code opening a new view)
}
}
Run Code Online (Sandbox Code Playgroud)
请记住,您仍然必须使用此属性,设置为UITableViewCellSelectionStyleNone不希望单元格可选时,并在您希望再次选择时设置回UITableViewCellSelectionStyleBlue(或UITableViewCellSelectionStyleGray).