Mam UITableView z UITableViewCells, który zawiera MKMapView.MKMapView wewnątrz UITableViewCell
Problem: jeśli komórka tabeli zostanie kiedykolwiek wybrana, a następnie przesuń mapę, zobaczysz, że widok mapy jest biały i widzisz tylko etykietę "Legal".
Czy ktoś wcześniej tego doświadczył?
Oto cały kod:
@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;
}
Próbowałem już tego, mogę potwierdzić, że to nie rozwiązuje problemu. – vgr
Ah, ok, co właściwie było przyczyną białej mapy w moim przypadku było ustawienie self.tableView.backgroundColor w viewWillAppear. Ustawienie tła widoku tła Kolor w widokuDidLoad nie powoduje problemu. Styl wyboru komórki nie ma znaczenia. – Eric
Jeśli to pomoże każdemu, jeśli używasz końcówki dla UITableViewCell, możliwe jest, że końcówka ma ustawiony selectionStyle na coś innego, niż jest ustawiane programowo. Stalówka może nie zostać załadowana, gdy wywołana zostanie funkcja cellForRowAtIndexPath (gdzie program set.selectionStyle zostanie ustawiony programowo), a następnie styl wyboru zostanie zresetowany do wartości w końcówce. – Duncan