裏面我有一個包含的MKMapView UITableViewCells一個UITableView。的MKMapView一個UITableViewCell
問題是:如果表格單元格曾經被選中,然後移動地圖,你看到的MapView全白了,你只看到了「法律」的標籤。
有沒有人遇到過這個?
這裏是整個代碼:
@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;
}
我已經試過了,可以證實,沒有解決不了的問題。 – vgr 2013-02-14 00:09:59
啊,確定究竟是什麼導致我的情況下的白色地圖是在viewWillAppear中設置self.tableView.backgroundColor。 在viewDidLoad中設置tableView的backgroundColor不會產生問題。 單元格的選擇風格並不重要。 – Eric 2013-02-14 04:33:48
在情況下,如果你的使用筆尖爲的UITableViewCell那麼它可能是筆尖有selectionStyle設置的東西比被設定編程不同,這可以幫助任何人。當調用cellForRowAtIndexPath(其中cell.selectionStyle以編程方式設置)時,nib可能尚未加載,然後將選擇樣式重置爲nib中的值。 – Duncan 2013-10-17 08:12:13