- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
...修改每6個單元而不是隻選定行的「accessoryType」。我錯過了什麼?
感謝
更新:這裏是小區創建代碼...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *TC = @"TC";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: TC];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlayerTableViewCell] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [NSString stringWithFormat:@"Person %d", row+1];
return cell;
}
我的解決方案基於以下明顯的答案是...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// EVERY row gets its one Identifier
NSString *TC = [NSString stringWithFormat: @"TC%d", indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: TC];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TC] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [NSString stringWithFormat:@"Person %d", row+1];
return cell;
}
如果有是我耳熟能詳的一種方式。如果我們可以根據在某一天傳遞的NSIndexPath更改特定單元格(至少對我來說看起來更加直觀),那將會很好。
是不是對的最佳做法?隨着行數增加,這會開始產生一些非常負面的性能影響嗎? – wgpubs 2010-04-15 08:54:42
好的,另一種方法: 檢查(rowNumber + 1)是否存在於一個winningNumbers數組中並替換cellForRowAtIndexPath方法中的附件。這也應該起作用。 – kovpas 2010-04-15 09:00:06