Question

I am in the middle of updating my app from an App Store version to a new version. My App is a simple UITableViewController that gets populated by the user clicking on a UINavigationBar button item and adding in information into UITextFields. When the user saves, the information gets saved to Core Data and the UITableViewController gets populated with NSFetchedResultsController.

The Model is simple: Transaction Entity with a notes attribute (there are others, but that's not relevant).

The existing App Store version does not have the ability for the user to create notes, but the new version does, with a UITextView in the Add Entry screen.

If the entry has a note, the UITableViewCell contains a pin image.

The pin is working throughout the app, but if I update from the App Store version to the new version, it shows a pin on all cells which should not be possible, considering they would of course not have notes. I know I'm missing something easy here but I can't quite figure it out:

This code is in my cellForRow:

self.pin = [[UIImageView alloc] initWithFrame:CGRectMake(13, 30, 24, 25)];
self.pin.image = [UIImage imageNamed:@"pin"];
self.pin.tag = 777;

if (!transaction.notes)
{
    NSLog(@"No notes");
    [[customCell viewWithTag:777] removeFromSuperview];

}

if ([transaction.notes isEqualToString:@""] || ([transaction.notes isEqualToString:@" "] || ([transaction.notes isEqualToString:@"  "] || ([transaction.notes isEqualToString:@"   "]))))
{
    NSLog(@"Remove Notes");
    [[customCell viewWithTag:777] removeFromSuperview];
}
else
{
    NSLog(@"Notes");
    [customCell addSubview:self.pin];

}

I'm initialising the self.pin in the viewDidLoad and the viewWillAppear as well.

I've added in the first if statement because in my head, the cells before the update should not have any notes.

When I run this code, all of the cells continue to have the pin the first time the app is run after the update.

Any guidance on fixing this issue would be really appreciated!

Was it helpful?

Solution

You need to update the UI on the Main Thread:

if (!transaction.notes) {
 dispatch_async (dispatch_get_main_queue (), ^{
      NSLog(@"No notes");
      [[customCell viewWithTag:777] removeFromSuperview];
                });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top