我想永久更改选定的单元格数据,就像我在我的didSelectRowAtIndexPath
方法中所做的那样,但问题是,当我选择一行时,单元格数据会发生变化,但是当我选择其他行时,前一个变成原样,而我还想要将数据保存到数组中,这些数组已被选中。这里是我的代码现在。如何永久更改选定的单元格数据?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
@try {
static NSString *cellidentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier];
if(cell == nil)
{
NSArray *cellObjects = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = (UITableViewCell*) [cellObjects objectAtIndex:0];
}
UILabel *label;
long row = [indexPath row];
label = (UILabel *)[cell viewWithTag:10];
label.text =time[row];
label.textColor = [UIColor blackColor];
cell.imageView.image = [img_clock_blue objectAtIndex:indexPath.row];
cell.backgroundColor = [UIColor yellowColor];
[tableView setSeparatorInset:UIEdgeInsetsZero];
//int hecValue;
return cell;
}
@catch (NSException *exception)
{
NSLog(@"%@",exception);
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView reloadData];
UITableViewCell *cell1 = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell1.imageView.image = [UIImage imageNamed:@"1_red.png"];
cell1.backgroundColor = [UIColor clearColor];
}
如果你需要保持原来选定的单元格,你需要保持它的轨道。现在你正在'didSelectRowAtIndexPath:'中重新加载表,所以之前选择的将被重新加载。 – Akhilrajtr
@Nasir发生这种情况是因为你在每次选择道路后重新加载tableview只是删除行[tableView reloadData];并尝试... –