MKMapView里面一个UITableViewCell [英] MKMapView inside a UITableViewCell

查看:185
本文介绍了MKMapView里面一个UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView与UITableViewCells包含一个MKMapView。



问题:如果表单元格被选中,然后移动地图,你看到的地图视图所有白色,你只看到法律标签。



有没有人经历过这个?





以下是整个代码:

  @implementation ViewController 

- (void)viewDidLoad
{
[super viewDidLoad];
//在加载视图之后执行任何其他设置,通常来自nib。
self.table.backgroundColor = [UIColor clearColor];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//处理可以重新创建的任何资源。
}

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


解决方案

/ p>

在我的例子中,地图变成白色,如果它的tableView或单元格有一个backgroundColor,它的单元格有一个灰色或蓝色的选择风格,单元格通过dequeue 。



我认为如果

  cell.selectionStyle = UITableViewCellSelectionStyleNone; 


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

解决方案

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;

这篇关于MKMapView里面一个UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆