Ios 如何在用户单击单元格时更改tableview图像

Ios 如何在用户单击单元格时更改tableview图像,ios,uitableview,Ios,Uitableview,我有一个表格视图,每个单元格有六个单元格,我设置了不同的颜色。我的问题是,当用户单击某个特定单元格时,我想将所有单元格的颜色都更改为橙色,但用户单击的单元格除外。试试这个 声明一个全局NSInteger变量。假设selectedIndex - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { selectedIndex = indexPath.row; [tab

我有一个表格视图,每个单元格有六个单元格,我设置了不同的颜色。我的问题是,当用户单击某个特定单元格时,我想将所有单元格的颜色都更改为橙色,但用户单击的单元格除外。

试试这个

声明一个全局NSInteger变量。假设
selectedIndex

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
selectedIndex = indexPath.row;
[tableview reload];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 if (indexPath.row == selectedIndex) { <set BG as some color> } else { <set BG as orange> } 
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath{
selectedIndex=indexPath.row;
[表视图重新加载];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
if(indexPath.row==selectedIndex){}else{}
}

那么,出了什么问题?您是否尝试使用方法?-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath{if(indepath.row==i){//reamin same color}否则if(indepath.row!=i){//将颜色设置为橙色}我使用了上述方法,但没有任何其他委托方法,如果有,请提及它。您可以提及委托方法并实现它吗?当您单击特定单元格时,
indexPath.row==i
将始终为真,因为
didselectrowatinexpath
仅使用所选单元格。您应该在此方法中循环所有单元格并更改其颜色。如果答案对您有帮助,您可以向上投票并单击此答案左侧的勾号图标吗。