MKMapView inside UITableViewCell

I have a UITableView with UITableViewCells that contains MKMapView.

Problem: if a table cell is ever selected, and then move the map, you will see that the map is completely white and you only see the “Legal” label.

Has anyone experienced this before?

screenshot

Here is the whole 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;
}
+5
source share
2 answers

I have experienced this.

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

I think that the card will not become as white if

cell.selectionStyle = UITableViewCellSelectionStyleNone;
+4
source

I also experienced it.

, / . TableView /, .

 cell.selectionStyle = UITableViewCellSelectionStyleNone;

... .

0

All Articles