如何禁用除UITableview
中的一个之外的所有UITableviewCell
的选择。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Deselect row
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// NSLog(@"Row Selected = %li",(long)indexPath.row);
self.selectedInvitedUserId = [[self.viewOrderUserArray valueForKey:@"InvitedUserId"] objectAtIndex:[indexPath row]];
NSLog(@"Row selectedInvitedUserId = %@",self.selectedInvitedUserId);
if( self.selectedInvitedUserId && [indexPath row] != 0 )
{
if ([[self.viewSelectedItemsArray lastObject] count] == 0)
{
[self performSegueWithIdentifier:@"delimenuFromViewOrderList" sender:self];
}
else
{
[self performSegueWithIdentifier:@"viewOrderSummaryFromOrderDetails" sender:self];
}
}
}
我知道这会禁用所有细胞。
cell.selectionStyle = UITableViewCellSelectionStyleNone;
您需要在中执行此操作
(UITableViewCell *)tableView:cellForRowAtIndexPath:
回调。这是一个单元格上的设置,当它被点击时将被执行。这不是你应该尝试手动管理的事情
像这样:
// Where indexPath != 0 points to the row you want to enable
if( self.selectedInvitedUserId && indexPath != 0 )
{
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
else
{
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
}
注意
这只会阻止它被突出显示。您需要在didSelectRowAtIndexPath:
回调内部检查其行是否正确。
以下是我的建议。
在CCD_ 4中保持CCD_。
现在您必须对didSelectRowAtIndexPath
采取行动。下面确实有点赞。
if( userId == your_ignore_userid )
{
// don't do anything
}
else
{
// do action - like go to another view controller
}
不在cellForRowAtIndexPath
中使用UITableViewCellSelectionStyleBlue
的原因是,如果用户点击该单元格(您不想允许),该单元格的背景将变为蓝色,这将违背您的应用程序设计,并且看起来很难看。
因此,我建议您在didSelectRowAtIndexPath
中处理操作。
如果您还有其他问题,请告诉我。
注:
使用cell.selectionStyle = UITableViewCellSelectionStyleNone;
时,仅禁用单元格选择。。你可以点击单元格,didSelectRowAtIndexPath
也会被调用。。。