【问题标题】:MKMapView inside a UITableViewCellUITableViewCell 内的 MKMapView
【发布时间】:2013-02-11 23:55:13
【问题描述】:

我有一个带有 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;
}

【问题讨论】:

    标签: cocoa-touch uitableview mkmapview


    【解决方案1】:

    我经历过。

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

    我觉得地图不会像这样变白

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    【讨论】:

    • 我已经试过了,可以确认没有解决问题。
    • 啊,好吧,在我的案例中,实际上导致白色地图的原因是在 viewWillAppear 中设置了 self.tableView.backgroundColor。在 viewDidLoad 中设置 tableView 的 backgroundColor 不会产生问题。单元格的选择样式无关紧要。
    • 如果这对任何人都有帮助,如果您为 UITableViewCell 使用笔尖,那么笔尖的 selectionStyle 设置可能与以编程方式设置的不同。调用 cellForRowAtIndexPath 时(其中 cell.selectionStyle 以编程方式设置)时笔尖可能尚未加载,然后选择样式被重置为笔尖中的值。
    【解决方案2】:

    我也经历过。

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

     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    ...确实有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2019-11-27
      相关资源
      最近更新 更多