Ios willSelectRowAtIndexPath不更改detailTextLabel
我正在使用Ios willSelectRowAtIndexPath不更改detailTextLabel,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在使用willselectRowatinedexpathdelegate方法更改所选单元格的detailTextLabel,即,我将\u00014d分配给所选单元格的detailTextLabel.text,并将@“分配给以前选择的单元格,问题是前一个单元格已分配了@“,但新选定的单元格上未出现\U0001F44D,代码如下: -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSInde
willselectRowatinedexpath
delegate方法更改所选单元格的detailTextLabel
,即,我将\u00014d
分配给所选单元格的detailTextLabel.text
,并将@“
分配给以前选择的单元格,问题是前一个单元格已分配了@“
,但新选定的单元格上未出现\U0001F44D
,代码如下:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *index = [NSIndexPath indexPathForRow:self.selectedCalcMethod inSection:0]; // index of previously selected cell
[self.mainTable cellForRowAtIndexPath:index].detailTextLabel.text=@"";
[self.mainTable cellForRowAtIndexPath:indexPath].detailTextLabel.text =@"\U0001F44D";
return indexPath;
}
不要像那样直接更改单元格内的任何值。更改您的模型(基础数据),然后在选择发生后(即运行循环完成后),调用表上的
reloadData
,以便表通过调用cellforrowatinexpath:
以通常方式获取正确的新值。您应该使用didselectrowatinexpath而不是willselectrowatinexpath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *index = [NSIndexPath indexPathForRow:self.selectedCalcMethod inSection:0]; // index of previously selected cell
[self.mainTable cellForRowAtIndexPath:index].detailTextLabel.text=@"";
[self.mainTable cellForRowAtIndexPath:indexPath].detailTextLabel.text =@"\U0001F44D";
return indexPath;
}
实际上,最好只重新加载“脏”索引路径,而不是整个索引路径table@kambala嗯,您可以调用
reloadRowsAtIndexPaths:withRowAnimation:
,但是如果您不想要动画,那么通过这样做,您获得的收益微乎其微,因为即使reloadData
也只会重新加载可见单元格的数据,而这些单元格很少,而另一方面,reloadRows
必须重新计算与reloadData
一样多的表布局。