Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapView inside a UITableViewCell

I have a UITableView with UITableViewCells that contains a MKMapView.

The Problem: if the table cell ever gets selected, then move the map, you see the mapview is all white and you only see the "Legal" label.

Has anyone experienced this before?

screenshot

Here is the entire code:

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.table.backgroundColor = [UIColor clearColor];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    MKMapView *map = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 220, 70)];

    MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01);
    CLLocationCoordinate2D logCord = CLLocationCoordinate2DMake(47.606, -122.332);
    MKCoordinateRegion region = MKCoordinateRegionMake(logCord, span);
    [map setRegion:region animated:NO];

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"aaaa"];
    [cell.contentView addSubview:map];

    return cell;
}
like image 946
vgr Avatar asked Oct 06 '22 02:10

vgr


1 Answers

I have experienced this.

In my case, the map becomes white like this if its tableView or cell has a backgroundColor and its cell has either a gray or blue selection style and the cell is recycled through dequeue.

I think that the map won't turn white like this if

cell.selectionStyle = UITableViewCellSelectionStyleNone;
like image 188
Eric Avatar answered Oct 10 '22 01:10

Eric