【发布时间】:2014-04-20 10:57:40
【问题描述】:
我有一个奇怪的 uitableview 选择问题。尝试在预选几个单元格的情况下使用多重选择。多选设置为真。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.font = [UIFont systemFontOfSize: 15.0f];
cell.textLabel.text = [data objectAtIndex:indexPath.row];
// if([_selectedInts containsObject:[NSNumber numberWithInt:(int)indexPath.row]]){
//
// [cell setSelected:YES animated:NO];
//
// } else {
//
// [cell setSelected:NO animated:NO];
//
// }
return cell;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.selectionStyle = UITableViewCellSelectionStyleGray;
[cell setUserInteractionEnabled:YES];
if([_selectedInts containsObject:[NSNumber numberWithInt:(int)indexPath.row]]){
[cell setSelected:YES animated:YES];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
} else {
[cell setSelected:NO animated:YES];
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
}
当 tableview 加载时,由于一个整数列表标记了需要选择的索引,因此选择了一堆单元格。
这些单元格停止响应,并且在被点击时不会发出 didselect 和 diddeselect 方法。
有什么问题?
【问题讨论】:
标签: ios objective-c uitableview