I’m sure this question is not unique, but I’ve not found other sources to solve it. Actually, those have been causing more confusion. Please shed light if you can.
The crux of the issue is that I want to slide (-50) a UILabel in ONE cell of a 7 section 30ish row table with custom cells. After scrolling a couple other rows are moving this label, and they continue to move farther and farther as the scrolling continues.
You’ll note that the minus 50 x coordinate is in 2 places for testing. The first one, in cell == nil, never gets called. Why?? I thought that was the place to solve this problem.
Also not sure how to call initWithStyle (not for custom) or initWithCoder (created in storyboard) even if the cell was nil. ??
NSArray *a = [[userDetailData objectAtIndex:[indexPath section]] objectAtIndex:[indexPath row]];
NSString *key = [[[a objectAtIndex:0] allKeys] objectAtIndex:0];
NSString *value = [[a objectAtIndex:0] valueForKey:key];
static NSString *CellIdentifier = @"MasterCell";
UsersTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// If cell does not exist, create it, otherwise customize existing cell for this row
if (cell == nil) {
// Create cell
cell = [[UsersTableViewCell alloc] initWithCoder:<#(NSCoder *)#>reuseIdentifier:CellIdentifier];
// Configure cell:
NSLog(@"Key: %@ %d, %d", key, [indexPath section], [indexPath row]);
// Prepare the date field to move left for checkmark or ex-mark
if ([key isEqualToString:@"Date"]) {
CGRect frame = cell.comboLabel.frame;
frame.origin.x -= 50;
cell.comboLabel.frame = frame;
NSLog(@"In Date... minus 50");
}
}
// Customize cell:
CGRect frame = cell.comboLabel.frame;
if ([key isEqualToString:@"Date"]) {
frame.origin.x -= 50;
cell.comboLabel.frame = frame;
NSLog(@" %d, %d\n cell: %@\n", [indexPath section], [indexPath row], cell);
}
else {
frame.origin.x += 0;
cell.comboLabel.frame = frame;
}
// Reset color
cell.comboLabel.textColor = [UIColor blackColor];
// Set the Item
cell.nameLabel.text = [NSString stringWithFormat: @" %@",key];
// Give the cell an accessory indicator
..... continue on with logic.
cell is not nil because you just assigned it to a reusable cell right before the if statement.
I would consider making a secondary prototype cell with an identifier like “Date Cell” and make a second set of reusable cells if the cell you are creating has key “Date”
here:
In fact, you probably won’t even need to do most of the customization of the cell if you just customize your prototype cell on the storyboard.