更改 uitableview 中的特定单元格 [英] Changing specific cells in uitableview
本文介绍了更改 uitableview 中的特定单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 uitableview,但我想禁用某些单元格并启用其他单元格.我使用以下代码禁用了除 cellForRowAtIndexPath
中的第一个之外的所有单元格:
I have a uitableview but I want to disable some cells and leave others enabled.
I used the following code to disable all cells except for the first in the cellForRowAtIndexPath
:
if ([indexPath row] > 0 ) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
cell.textLabel.textColor = [UIColor lightGrayColor];
}
但不是禁用所有单元格并启用第一个单元格,而是禁用所有单元格并启用最后一个单元格.为什么会发生这种情况?我该怎么做才能让它发挥作用?
But instead of disabling all cells and enabling the first, it disabled all cells and enables the last. Why does this happen? And what can I do to get it to work?
顺便说一句,这是我所有 cellForRowAtIndexPath 的代码:
BTW Here's my code for all cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
sectionContents = [[self listOfItems] objectAtIndex:[indexPath section]];
contentsForThisRow = [sectionContents objectAtIndex:[indexPath row]];
if ([indexPath row] > 0 ) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
cell.textLabel.textColor = [UIColor lightGrayColor];
}
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = contentsForThisRow;
return cell;
}
推荐答案
用这个替换你的 cellForRowAtIndexPath:
代码
Replace your code of cellForRowAtIndexPath:
with this one
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
sectionContents = [[self listOfItems] objectAtIndex:[indexPath section]];
contentsForThisRow = [sectionContents objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = contentsForThisRow;
if ([indexPath row] > 0 ) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
cell.textLabel.textColor = [UIColor lightGrayColor];
}
return cell;
}
这篇关于更改 uitableview 中的特定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文