您在cellForRowAtIndexPath
中使用dequeueReusableCellWithIdentifier
?
你應該有這樣的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *reuseIdentifier = @"myTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[ArticleTableViewCell alloc] init];
}
// customise cell here (like cell.title = @"Woopee";)
if (self.selectedCells containsObject:[NSString stringWithFormat:@"%d", indexPath.row]] {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
}
return cell;
}
擴大對對方的回答,您可以通過做這樣的事情與跟蹤是否有特定的細胞先前已經選擇(被因此應該被禁用)的以上:
聲明屬性像@property (nonatomic, strong) NSMutableArray *selectedCells;
則:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
[self.selectedCells addObject:[NSString stringWithFormat:@"%d", indexPath.row]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
}
我的筆記本電腦將死,但如果它墜毀你應該看看初始化單元的代碼(alloc和init),或者保留之前的代碼。
你爲什麼'cell.userInteractionEnabled = NO;'? – fannheyward
@fannheyward,因爲我不希望該單元格被點擊一次後纔可用。 –