我有一個tableview,我需要每次選擇一行時顯示一個複選標記。 (多選)我的代碼如下。我也能夠取消選擇一行。問題:正在重用多個選擇tableview單元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *RootViewControllerCell = @"RootViewControllerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
if(nil == cell)
{
cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
}
cell.textLabel.font = [UIFont fontWithName:[NSString stringWithFormat:@"HelveticaNeue-Bold"] size:12];
textView.textColor = [UIColor colorWithRed:0.281 green:0.731 blue:0.8789 alpha:1];
cell.textLabel.text = [optionsArray objectAtIndex:[indexPath row]];
if (pathIndex == indexPath)
{
if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
pathIndex = indexPath;
[surveytableView reloadData];
}
但我有一個單元格被重用的問題。當我選擇一個單元另一個單元其他地方也被選中。只有複選標記(或沒有複選標記)纔會被重用,其他細節(如行標題等)不會被重用。任何解決方案來解決這個提前致謝。
我發現從堆棧溢出回答另一個問題一個解決方案: http://stackoverflow.com/questions/6023883/ uitableview-multiple-checkmark-selection Folllow this above link。似乎現在對我來說工作得很好。 – 2011-06-14 07:33:29