Hi there, been having this problem for a few days now and can't seem to find a solution for it. It's probably some very basic stuff but still can't come up with a solution.
I have a bunch of labels nested inside table view cells with an edit navigation controller button that goes to another table view. This table view has text fields that store data into an SQLite database. The labels return certain values from the database. Now this part works perfectly. But when I update a text field and navigate back to the labels the label is not updated,if I scroll the table so that the modified cell is out of the view then it gets updated, so think the problem is that the cell still has the old value cached and only releases it once its dequeued.
Part of the code:(at least i think this is what matters as this is where the cells are created)
Any help is welcome. Thanks
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ContactsDetailCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
int row = [indexPath row]; int section = [indexPath section];
NSDictionary *resultSet = [sqliteManager queryRow:[NSString stringWithFormat:@"SELECT * FROM contacts WHERE id = %d;", contactsId]];
switch (section) { case 0: switch (row) { case 0: cell.textLabel.text = @"Name:";
UILabel *nameLabel = [[UILabel alloc] initWithFrame: CGRectMake(90, 10, 200, 25)];
nameLabel.text = [resultSet objectForKey:@"name"];
nameLabel.textColor = [UIColor blackColor];
nameLabel.font = [UIFont systemFontOfSize:17.0];
nameLabel.backgroundColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView addSubview:nameLabel];
[nameLabel release];
break;
case 1:
cell.textLabel.text = @"Address:";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UILabel *addressLabel = [[UILabel alloc] initWithFrame: CGRectMake(90, 10, 200, 25)];
addressLabel.text = [resultSet objectForKey:@"address"];
addressLabel.textColor = [UIColor blackColor];
addressLabel.font = [UIFont systemFontOfSize:17.0];
addressLabel.backgroundColor = [UIColor whiteColor];
[cell.contentView addSubview:addressLabel];
[addressLabel release];
break;
default:
break;
} break; default: break;