MKMapView inside a UITableViewCell

。_饼干妹妹 提交于 2019-12-07 05:28:26

问题


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?

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;
}

回答1:


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;



回答2:


I have experienced this as well.

My map had white background when it was touched after pushing/popping another detail view controller. TableView has no color/background configured yet, everything is default.

 cell.selectionStyle = UITableViewCellSelectionStyleNone;

...actually helped.



来源:https://stackoverflow.com/questions/14823185/mkmapview-inside-a-uitableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!