我有一个表格视图,其中显示了一些记录。并导航到第二个视图,在第二个视图控制器中,我们有四个选项,分别是初级、次级、第三级、第四级。当用户选择此选项中的任何一个时,它将导航到后面,并且选定的单元格颜色将改变。
所有选项都运行良好。但我坚持以下问题,
假设用户选择第一个单元格并将其设置为 pri,它将向后导航并且颜色将为红色,但是当用户选择另一个单元格(假设 5 个单元格)并再次设置为主要单元格时,单元格 1 将保持与红色相同。我不想要这个。一次用户不会将一条记录设置为 pri/sec/ter/quaternary。
我将如何管理这个?试图重新加载表数据,但不工作??在导航回来时,我在视图中使用下面的代码将出现
if (singltong.primary == indes) {
[tbleMasjidnames cellForRowAtIndexPath:tableSelection].backgroundColor = [UIColor colorWithRed:13.0f/255.0f green:159.0f/255.0f blue:78.0f/255.0f alpha:1.0f];
}
else if (singltong.secondary == indes){
[tbleMasjidnames cellForRowAtIndexPath:tableSelection].backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:33.0f/255.0f blue:59.0f/255.f alpha:1.0f];
}
else if (singltong.tertiary == indes){
[tbleMasjidnames cellForRowAtIndexPath:tableSelection].backgroundColor = [UIColor colorWithRed:23.0f/255.0f green:153.0f/255.0f blue:221.0f/255.0f alpha:1.0f];
}
else if (singltong.quaternary == indes){
[tbleMasjidnames cellForRowAtIndexPath:tableSelection].backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:150.0/255.0 blue:23.0f/255.0f alpha:1.0f];
}
//********************Cell for row****************
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MasjidCell"; // Custom cell for masjid Name
MasjidListCell *cell = (MasjidListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor greenColor];
if (cell == nil){
NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"MasjidCell" owner:self options:nil];
cell = nib[0];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
//if search is on then get data from search result array else from shared instance
if (_isSearchOn) {
if ([searchResults count]==0) {
cell.lblMasjidName.text=@"No Record Found.";
}
else{
cell.lblMasjidName.text = [searchResults objectAtIndex:indexPath.row];
}
}
else{
cell.lblMasjidName.text = singltong.MasjidNames[indexPath.row];
cell.lblLocalArea.text = singltong.masjidLocalArea[indexPath.row];
cell.lblCountry.text = singltong.masjidCountry[indexPath.row];
}
return cell;
}//方法结束