Note that there are some explanatory texts on larger screens.

plurals
  1. POTableView Cell Custom type Text Overlaps itself or is Blank
    text
    copied!<p>Hoping someone can advise me on the correct method to populate a <code>UITableViewCell</code> with custom labels. I keep running into the same issues , either the label is blank or when the table fills up with <code>cells</code> reused ones show overlapping <code>label</code> text.</p> <p>I have followed what has been advised for others here but each way I do it something breaks.</p> <p>** Update **</p> <p>I have changed the code to below and have most of it working except when I select a cell the label overlaps as in the screenshot below. The code for the tutorial I am using can be found here: <a href="https://github.com/funkyboy/Core-Data-on-iOS-5-Tutorial--How-To-Work-with-Relations-and-Predicates" rel="nofollow noreferrer">https://github.com/funkyboy/Core-Data-on-iOS-5-Tutorial--How-To-Work-with-Relations-and-Predicates</a></p> <p>Here is my code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } FailedBankInfo *info = [_fetchedResultsController objectAtIndexPath:indexPath]; CGRect infoFrame = CGRectMake(10, 10, 200, 16); UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoFrame]; infoLabel.textColor = [UIColor blackColor]; infoLabel.backgroundColor = [UIColor yellowColor]; infoLabel.font = [UIFont systemFontOfSize:12]; infoLabel.textAlignment = NSTextAlignmentCenter; infoLabel.tag = indexPath.row; infoLabel.text = [NSString stringWithFormat:@"%@, %@", info.city, info.state]; [cell addSubview:infoLabel]; return cell; } - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { FailedBankInfo *info = [_fetchedResultsController objectAtIndexPath:indexPath]; UILabel *theLabel = (UILabel *)[cell.contentView viewWithTag:indexPath.row]; theLabel.text = [NSString stringWithFormat:@"%@, %@", info.city, info.state]; } </code></pre> <p>Because I am using the Prototype <code>Cell</code> with Core Data and <code>fetchedresultcontroller</code> the <code>if(!cell)</code> is never called. I changed the tag to be the indexPath.row number. Every tutorial I have followed works fine if you use the predefined <code>cell</code> types. If I use Custom with my own labels it never works out. Should I not use a fetchedresultscontroller for the tableview data? If I change the city title in the detail view and save it the following code gets called:</p> <pre><code>- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { UITableView *tableView = self.tableView; switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeUpdate: [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; break; case NSFetchedResultsChangeMove: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; } } </code></pre> <p>Here are some screenshots:</p> <p><img src="https://i.stack.imgur.com/fnrir.png" alt="storyboard"></p> <p><img src="https://i.stack.imgur.com/55iYy.png" alt="changed cell"></p> <p><img src="https://i.stack.imgur.com/AGWCE.png" alt="selected cell"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload