UITableViewCell에 MKMapView가 임베드되어 있습니다. 때때로 섹션이 다시로드됩니다. 문제는지도 셀이 새로 고침이 발생할 때 갑자기 흰색으로 이동하기로 결정한 것입니다.UITableViewCell이 다시로드 된 후 MKMapView가 흰색으로 바뀜
다음은 기본 코드
- (void)viewDidLoad
{
[super viewDidLoad];
_mapCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Map"];
[_mapCell setSelectionStyle:UITableViewCellSelectionStyleNone];
[_mapCell setBackgroundColor:[UIColor greenColor]];
_mapView = [[MKMapView alloc] init];
[_mapView setTranslatesAutoresizingMaskIntoConstraints:NO];
[_mapCell.contentView addSubview:_mapView];
[_mapCell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_mapView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_mapView)]];
[_mapCell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_mapView]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_mapView)]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[_mapCell setSelectionStyle:UITableViewCellSelectionStyleNone];
return _mapCell;
}
그리고 다시로드 코드
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
});
}
Here is the sample project to demonstrate the problem.
주 :지도와 함께 사용하는 경우의 tableview에 대한 JIT는 랙이있다. 따라서, 나는 그것을 위해 iVar를 생성하고 그것을 더 일찍 초기화한다.
당신은 viewDidAppear의 슈퍼 구현을 호출하는 것을 잊었다 작동합니다. –
사실, 그게 이유가 아니었지만. (빨리 쓰고 싶었고 놓쳤습니다.) (Added) – Byte