[英]In UiTableView didSelectRowAtIndexPath updating wrong Cell
在我的TableView中,didSelectRowAtIndexPath仅更新每个单元格上表的最后一个可见单元格。
这是示例代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView isEqual:subcategoryTV])
{
selCell=(MDTableViewCell *)[subcategoryTV cellForRowAtIndexPath:indexPath ];
if ([checkButton.titleLabel.text isEqualToString:@"✓"])
{
checkButton.backgroundColor=[UIColor clearColor] ;
[checkButton setTitle:resetTitle forState:UIControlStateNormal];
[checkButton setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
checkButton.layer.borderColor = [UIColor lightGrayColor].CGColor;
}
else
{
resetTitle=checkButton.titleLabel.text;
NSLog(@"%@",resetTitle);
checkButton.backgroundColor=[UIColor colorWithRed:1 green:0.839 blue:0.314 alpha:1] ;
[checkButton setTitle:@"✓" forState:UIControlStateNormal];
[checkButton.titleLabel setFont:[UIFont fontWithName:@"Futura" size:25]];
[checkButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
checkButton.layer.borderColor = [UIColor clearColor].CGColor;
}
if (costLabel.hidden==YES) {
costLabel.hidden=NO;
}
else
{
costLabel.hidden=YES;
}
}
}
无论如何,您都不应该从单元格中查询数据,而应该检查模型以确定要做什么。 用户更改了任何行或按钮后,您将更新模型,然后使用该模型来更新视图。 这是正确的方法。
在这里,您的特定问题(使用错误的方法)是将单元格移至选定的索引路径,然后不使用它。 您应该从单元格中获取按钮和标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.