Note that there are some explanatory texts on larger screens.

plurals
  1. PONSFetchedResultsChangeMove displaying incorrect label in custom UITableViewCell
    primarykey
    data
    text
    <p>I'm pretty sure there is an easier way to do this that I'm missing in all my reading...but this is driving me insane. I am very tired - and do apologize if this gets verbose.</p> <p>I'm using an NSFetchedResultsController in my app - very standard issue - and it works. Two sections, ordered properly, etc. When a user taps a cell in the first section (the BOOL value of the property creating the two sections is reversed) - it moves to the second section (BOOL value flipped again) - and vice versa...again, works famously.</p> <p>Here's where my implementation gets a little funky. Eventually I want to support iAds - according to the HIG these should be placed at the bottom of the screen...the easiest way I found to do this is to put the UITableView inside a UIView, to avoid some logical reasons that escape me now - but that's what I have - UIView with a UITableView.</p> <p>I'm using Storyboards with prototype cells - two to be specific. One is used for adding content and acts as the delimiter between the two sections. The other is the default cell to display. When I register IBOutlets for this cell - it throws an exception (which is an issue, but I'm able to work around it). So, instead, what I've been doing is using cell.contentView.subviews to get to the elements I need to mess with:</p> <pre><code> NSArray *cellSubViews = cell.contentView.subviews; if ([cellSubViews count] == 3) { // editing accessory view cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator; // default background image view cell.backgroundView = self.defaultClockCellBackgroundImageView; // clock name label UILabel *clockNameLabel = [cellSubViews objectAtIndex:2]; clockNameLabel.text = clock.name; clockNameLabel.textColor = (indexPath.section == 0 &amp;&amp; ![clock.isAddClockCell boolValue]) ? [UIColor whiteColor] : [UIColor lightTextColor]; // view child button UIButton *viewChildButton = [cellSubViews objectAtIndex:0]; UIImage *viewChildClocksButtonBackgroundImage; if (self.clockForFetch != nil) { //NSLog(@"child clocks list - N/A"); viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"childcell_blank"]; viewChildButton.enabled = NO; } else if ([clock.childClocks count] &lt; 2) { //NSLog(@"add child button"); viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"parentcell_addchild"]; } else if (![clock.isRunning boolValue] || [self totalChildClocksRunning:clock] &lt; 1) { //NSLog(@"view child button"); // children clocks cannot be running while parent is stopped; // therefore, no need to actually check // this solves the "wait for cell animation to end" issue // without the need for tableview reload data viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"parentcell_viewchild"]; } else { //NSLog(@"view child running button"); viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"parentcell_viewchild_running"]; } [viewChildButton setImage:viewChildClocksButtonBackgroundImage forState:UIControlStateNormal]; viewChildButton.hidden = NO; // view time entries list for clock UIButton *detailDisclosureButton = [cellSubViews objectAtIndex:1]; UIImage *detailDisclosureButtonBackgroundImage = (self.clockForFetch == nil) ? [UIImage imageNamed:@"parentcell_detaildisclosure"] : [UIImage imageNamed:@"childcell_detaildisclosure"]; [detailDisclosureButton setImage:detailDisclosureButtonBackgroundImage forState:UIControlStateNormal]; detailDisclosureButton.hidden = NO; if (self.editing) { viewChildButton.hidden = YES; detailDisclosureButton.hidden = YES; } } </code></pre> <p>Please note: prior to this method I was using a separate NIB with IBOutlets and could replicate the issue - just not as consistently.</p> <p>Here is the table with three cells that move when tapped (Alpha, Beta, and Gamma)...ah, no images to new sorry - wish they could have told me that before I uploaded the images - enter ASCII art:</p> <pre><code>--------------- | alpha | --------------- | beta | --------------- | gamma | --------------- | *delimiter* | --------------- </code></pre> <p>Here is the table after tapping the Alpha and Beta cells:</p> <pre><code>--------------- | gamma | --------------- | *delimiter* | --------------- | beta | --------------- | beta | --------------- </code></pre> <p>However, if I tap on the custom detail disclosure button in the first cell labeled "Beta" (which should read Alpha), I get the correct object passed to the detail view:</p> <pre><code>-------------------------------------------- | &lt; back detail view for alpha edit | -------------------------------------------- </code></pre> <p>So, the fetched results controller is being updated - it just doesn't seem to be configuring things consistently when it talks to the table view. In the configure cell method above I've checked to see the names of the objects found in the controller - and they are also correct; i.e., the first beta cell (cell for row at index path 1,0) is Alpha - not Beta - even though the table view displays Beta.</p> <p>I keep seeing mention of custom cells needing setNeedsDisplay and/or setNeedsLayout, but I don't think I'm quite understanding that one - though I have tried putting it almost everywhere I could think of in the code. "NSFetchedResultsChangeMove" is what gets called when the user taps a cell - and I've tried a lot of the variations I've seen on the web (including here) to fix glitches that I thought were similar - to no avail.</p> <p>I'm sure this construct will mature over time (as this is a first go) but, as I said, I encountered the same issue with a completely different construct (storyboards didn't exist at the time) - and could still repeat the issue.</p> <p>Any assistance would be greatly appreciated. And, if there is an answer on here for this exact same issue, I do apologize for the repeat.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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