在UITableViewCell里面的MKMapView

vgr*_*vgr 5 cocoa-touch uitableview mkmapview

我有一个UITableView与UITableViewCells,其中包含MKMapView.

问题:如果表单元格被选中,然后移动地图,您会看到mapview全部为白色,您只看到"Legal"标签.

有谁之前经历过这个吗?

截图

这是整个代码:

@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;
}
Run Code Online (Sandbox Code Playgroud)

Eri*_*ric 4

我有过这样的经历。

就我而言,如果其 tableView 或单元格具有背景颜色,并且其单元格具有灰色或蓝色选择样式,并且单元格通过出队进行回收,则地图会变成这样的白色。

我认为地图不会像这样变白

cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)

  • 啊,好吧,在我的例子中,实际上导致白色地图的原因是在 viewWillAppear 中设置 self.tableView.backgroundColor 。在viewDidLoad中设置tableView的backgroundColor不会产生问题。单元格的选择样式并不重要。 (2认同)