我有一个UITableView
填充了27行。我正在尝试更改所选单元格的accessoryType
。我在didSelectRowAtIndexPath:
委托方法中这样做。didSelectRowAtIndexPath一次选择多个行
我面临的问题是,当选择一行并更改单元格的accessoryType
时,该行的第11行也会被修改。
我试过打印[indexPath row]
的值,但它只显示被选中的行而不是另一个。
我很困惑这样的东西;请帮助我。
添加的代码cellForRowAtIndexPath
方法
UITableViewCell *cell;
if ([indexPath row] == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"acell"];
}
else {
cell = [tableView dequeueReusableCellWithIdentifier:@"bcell"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell == nil && [indexPath row] != 0) {
cell = [[[UITableViewCell alloc] initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:@"bcell"] autorelease];
}
else if(cell == nil && [indexPath row] == 0){
cell = [[[UITableViewCell alloc] initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:@"acell"] autorelease];
}
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}
if ([indexPath row] == 0) {
cell.textLabel.text = @"Select All";
cell.textLabel.font = [UIFont boldSystemFontOfSize:13.0f];
}
else {
cell.textLabel.text = @"Some Text Here"
cell.detailTextLabel.text = @"Another piece of text here"
}
return cell;
我做%10
因为行为11行后重复,因此试图为每11行创建新的对象。
我didSelectRowAtIndexPath
methos代码
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
if ([indexPath row] != 0) {
NSIndexPath *tempIndex = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:tempIndex];
tempCell.accessoryType = UITableViewCellAccessoryNone;
}
cell.accessoryType = UITableViewCellAccessoryNone;
}
else{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
if ([indexPath row] == 0) {
for (int i = 0; i < [dataSource count]; i++) {
NSIndexPath *tempIndex = [NSIndexPath indexPathForRow:i+1 inSection:0];
UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:tempIndex];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
tempCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else{
tempCell.accessoryType = UITableViewCellAccessoryNone;
}
}
}
请帮我多选或任何其它的方式来解决多重选择的问题。
在此先感谢!
发布您的代码可能是?最有可能你正在重用cellFor错误在cellForRowAtIndexPath方法 – Vladimir 2011-05-19 11:21:29
张贴您的cellforrowindex tableview代码 – 2011-05-19 11:26:20
检查http://stackoverflow.com/questions/4616345/select-multiple-rows-in-uitableview/4616432例如 – Vladimir 2011-05-19 12:35:57