2013-02-11 33 views
5

裏面我有一個包含的MKMapView UITableViewCells一個UITableView。的MKMapView一個UITableViewCell

問題是:如果表格單元格曾經被選中,然後移動地圖,你看到的MapView全白了,你只看到了「法律」的標籤。

有沒有人遇到過這個?

screenshot

這裏是整個代碼:

@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

我曾經歷過這一點。

以我的情況下,地圖變成白色像這樣,如果其的tableView或小區具有的backgroundColor及其電池具有無論是灰色或藍色選擇風格和細胞通過出隊再循環。

我認爲,地圖也不會變白這樣如果

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
+1

我已經試過了,可以證實,沒有解決不了的問題。 – vgr 2013-02-14 00:09:59

+2

啊,確定究竟是什麼導致我的情況下的白色地圖是在viewWillAppear中設置self.tableView.backgroundColor。 在viewDidLoad中設置tableView的backgroundColor不會產生問題。 單元格的選擇風格並不重要。 – Eric 2013-02-14 04:33:48

+0

在情況下,如果你的使用筆尖爲的UITableViewCell那麼它可能是筆尖有selectionStyle設置的東西比被設定編程不同,這可以幫助任何人。當調用cellForRowAtIndexPath(其中cell.selectionStyle以編程方式設置)時,nib可能尚未加載,然後將選擇樣式重置爲nib中的值。 – Duncan 2013-10-17 08:12:13

0

我曾經歷過這一點。

我的地圖了,當它被推/彈出另一個細節視圖控制器後觸及白色背景。 TableView沒有配置顏色/背景,一切都是默認的。

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

......實際上有幫助。