Whenever a cell from section 3 is selected. I'm updating the DataSource array, and the cell's background color is thus changing correctly.
However, whenever I scroll back up I start seeing random cells with the modified background color, knowing that I don't even mention it in my cellForRowAtIndexPath
method and each section in my tableView
is populated from a separate DataSource Array/Dictionary
!
(I'm using a Storyboard to handle all UI setup)
Here's my code (focus on Section 3)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ECTextFieldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kSettingsTextFieldCellReuseIdentifier
forIndexPath:indexPath];
if (indexPath.section == 0) {
cell.cellTextField.text = [self.personalInfoDataSource valueForKey:kUserValuesKey][indexPath.row];
} else if (indexPath.section == 1) {
cell.cellTextField.text = [self.contactInfoDataSource valueForKey:kUserValuesKey][indexPath.row];
} else if (indexPath.section == 2) {
cell.cellTextField.text = [self.professionalDetailsDataSource valueForKey:kUserValuesKey][indexPath.row];
} else if (indexPath.section == 3) { //---- Problems here
UserMeta *metaObj = self.interestDataSource[indexPath.row];
cell.cellTextField.userInteractionEnabled = NO;
cell.cellTextField.text = metaObj;
if (self.user.INTEREST.count > 0 && [self.user.INTEREST contains:metaObj.name] ) {
cell.backgroundColor = [UIColor redColor];
}
}
return cell;
}
And here's where I'm doing all the DataSource modifications
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 2) {
// Do Stuff
} else if (indexPath.section == 3) { //---- Problems here
ECTextFieldTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
UserMeta *metaObj = self.interestDataSource[indexPath.row];
[self.user.INTEREST addObject:metaObj];
}
}