UITableViewCell not updating after location callback until scroll or selection

autobahn

I am trying to update a UITableViewCell as soon as the user's location is found and reverse-geocoded.

From reading lots of other answers to similar questions, it seems the tableview reload must occur on the main thread, which I have tried without any success.

All the location data gets retrieved correctly, and is correctly added to the core data object, but the tableview cell simply is not updating until the user scrolls or the cell is selected, at which point the cell is correctly updated from that point on.

Here is a selection from my code - does anyone know why the tableview cell isn't updating right away?

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations  // Delegate callback method.
{       

    // Correctly gets currentLocation coordinates.
    ...
    CLLocation *currentLocation = [locations lastObject];
    ...

    // Reverse-geocode the coordinates (find physical address):
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {

        if (error == nil && [placemarks count] > 0) {
            CLPlacemark *placemark = [placemarks lastObject]; // Correctly gets placemark.

            //    Correctly adds placemark to core data object.
            ...
            ...

            // Reload TableView:
            //    [self.tableView reloadData];  //Tried this, didn't work, since not on main thread.
            //    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];  //Doesn't work.
            //    [self performSelector:(@selector(refreshDisplay)) withObject:nil afterDelay:0.5];  //Doesn't work.
            [self performSelectorOnMainThread:@selector(refreshDisplay) withObject:nil waitUntilDone:NO];  //Doesn't work.
        }
    }];
}

- (void)refreshDisplay {
    [_tableView reloadData];
}

Again, the underlying logic is working, since the data gets added correctly and eventually shows up on the cell, but not until user scroll or selection. I can't imagine why this doesn't refresh the tableviewcell right away. Does anyone have any idea?

UPDATE: My Solution

The missing piece was adding [cell layoutSubviews] just after the cell is created/dequeued. The detailTextLabel now updates correctly. Apparently this may be related to an iOS8 bug that doesn't update the detailText if it starts out nil (i.e. no content), and layoutSubviews makes it so it is not nil, by initializing all the subviews of the cell (as far as I understand). I got this suggestion from here:

ios 8 UITableViewCell detail text not correctly updating

The accepted answer also helped me figure out this missing piece.

jsetting32

You should get a reference to the cell that you want to update

Ex. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:theRow inSection:theSection]];

Then [[cell textLabel] setText:theLocation];

If your updating multiple cells just get multiple references of the cells you want to update and update them accordingly.

Typically anything dealing with UI components that need updating should be done on the main thread. I have come across this issue before but if you want to have a solution dealing with threading, what you have done seems like it should work.

Here is the GCD solution:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.table reloadData];
});

But according to what you've done, it shouldn't help... It is basically the same thing just with GCD. Hopefully the solution I gave you at the beginning works...

EDIT

Within your - (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath

    cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

Did you set the style to UITableViewCellStyleDefault?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

After scroll, UILabel not updating in UITableViewCell

From Dev

UITableViewCell not updating after selection on iOS 7

From Dev

UITableViewCell not updating after selection on iOS 7

From Dev

UITableViewCell content shifting after selection

From Dev

UITableViewCell gets duplicated after scroll

From Dev

UITableViewCell gets duplicated after scroll

From Dev

Adding CALayer to UITableViewCell removed after scroll

From Dev

UITableView Row Selection Returns Wrong Index Path Until Scroll

From Dev

View not updating after change in Google API callback

From Dev

Updating Label text after OptionMenu selection changes

From Dev

Time not updating in label after selection in TimePicker

From Dev

Set Map location after successful $http callback

From Dev

jQuery - stop/cancel scroll event callback after a certain scroll position

From Dev

$location not updating after each URL click

From Dev

Image not showing on my UIImageview after clicking on UICollectionview cell until scroll

From Dev

Delay AFTER UPDATE execution until other updating processes are completed

From Dev

Rails: updating model triggers after_save callback "on: :create"

From Dev

Rails: updating model triggers after_save callback "on: :create"

From Dev

How to manipulate scroll position after updating gridview row?

From Dev

UITableViewCell on selection highlighting color

From Dev

make UITableViewCell selection blink

From Dev

UITableViewCell on selection highlighting color

From Dev

UITableViewCell selection challenge

From Dev

UIStackView not updating after updating height of subview (UITableView with no scroll) while inside a ScrollView

From Dev

Updating UITableViewCell contents with UIStepper

From Dev

Custom UITableViewCell not updating

From Dev

UITableViewCell - Updating NSMutableDictionary Values

From Dev

Custom UITableViewCell not updating properly

From Dev

Custom UITableViewCell not updating

Related Related

  1. 1

    After scroll, UILabel not updating in UITableViewCell

  2. 2

    UITableViewCell not updating after selection on iOS 7

  3. 3

    UITableViewCell not updating after selection on iOS 7

  4. 4

    UITableViewCell content shifting after selection

  5. 5

    UITableViewCell gets duplicated after scroll

  6. 6

    UITableViewCell gets duplicated after scroll

  7. 7

    Adding CALayer to UITableViewCell removed after scroll

  8. 8

    UITableView Row Selection Returns Wrong Index Path Until Scroll

  9. 9

    View not updating after change in Google API callback

  10. 10

    Updating Label text after OptionMenu selection changes

  11. 11

    Time not updating in label after selection in TimePicker

  12. 12

    Set Map location after successful $http callback

  13. 13

    jQuery - stop/cancel scroll event callback after a certain scroll position

  14. 14

    $location not updating after each URL click

  15. 15

    Image not showing on my UIImageview after clicking on UICollectionview cell until scroll

  16. 16

    Delay AFTER UPDATE execution until other updating processes are completed

  17. 17

    Rails: updating model triggers after_save callback "on: :create"

  18. 18

    Rails: updating model triggers after_save callback "on: :create"

  19. 19

    How to manipulate scroll position after updating gridview row?

  20. 20

    UITableViewCell on selection highlighting color

  21. 21

    make UITableViewCell selection blink

  22. 22

    UITableViewCell on selection highlighting color

  23. 23

    UITableViewCell selection challenge

  24. 24

    UIStackView not updating after updating height of subview (UITableView with no scroll) while inside a ScrollView

  25. 25

    Updating UITableViewCell contents with UIStepper

  26. 26

    Custom UITableViewCell not updating

  27. 27

    UITableViewCell - Updating NSMutableDictionary Values

  28. 28

    Custom UITableViewCell not updating properly

  29. 29

    Custom UITableViewCell not updating

HotTag

Archive