MKMapView goes white after reloading UITableViewCell

I have MKMapView built into UITableViewCell. From time to time, the partition is reloaded. The problem is that the map cell decided to run all of a sudden when an update occurs.

Here is the base code

- (void)viewDidLoad
{
    [super viewDidLoad];

    _mapCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Map"];
    [_mapCell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [_mapCell setBackgroundColor:[UIColor greenColor]];

    _mapView = [[MKMapView alloc] init];
    [_mapView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [_mapCell.contentView addSubview:_mapView];

    [_mapCell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_mapView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_mapView)]];
    [_mapCell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_mapView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_mapView)]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [_mapCell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return _mapCell;
}

And the reboot code

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    });
}

Here is an example project to demonstrate the problem.


Note: JIT for tableview is logical if used with maps. Therefore, I created iVar for it and launched it earlier.

+3
source share
2 answers

From docs

reloadSections:withRowAnimation:
Reloads the specified sections using a given animation effect.

- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
Parameters
sections  An index set identifying the sections to reload.
animation A constant that indicates how the reloading is to be animated, for 

The animation constant affects the direction in which both the old and the new section rows slide. For example, if the animation constant is UITableViewRowAnimationRight, the old rows slide out to the right and the new cells slide in from the right.
Discussion
Calling this method causes the table view to ask its data source for new cells for the specified sections. The table view animates the insertion of new cells in as it animates the old cells out. Call this method if you want to alert the user that the values of the designated sections are changing. If, however, you just want to change values in cells of the specified sections without alerting the user, you can get those cells and directly set their new values.

In particular

, . , UITableViewRowAnimationRight, .

, . .

, , , .

UITableViewRowAnimationNone

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
+2

, . :

[CATransaction begin]; 

[CATransaction setCompletionBlock:^
{ 
     [self.tableView reloadData];
}];

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]    
              withRowAnimation:UITableViewRowAnimationAutomatic];

[CATransaction commit];

, .

+1

All Articles