5

我有一个带有 UITableViewCells 的 UITableView,其中包含一个 MKMapView。

问题:如果表格单元格被选中,然后移动地图,你会看到地图视图全是白色的,你只会看到“合法”标签。

有谁之前经历过这个吗?

截屏

这是整个代码:

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

2 回答 2

4

我有过这种经历。

在我的情况下,如果它的 tableView 或单元格具有 backgroundColor 并且其单元格具有灰色或蓝色选择样式并且该单元格通过出队回收,则地图会变成这样的白色。

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

cell.selectionStyle = UITableViewCellSelectionStyleNone;
于 2013-02-12T19:39:24.823 回答
0

我也经历过这种情况。

在推送/弹出另一个详细视图控制器后触摸我的地图时,我的地图有白色背景。TableView 还没有配置颜色/背景,一切都是默认的。

 cell.selectionStyle = UITableViewCellSelectionStyleNone;

……确实有帮助。

于 2013-02-23T13:08:21.400 回答