2014-02-25 2 views
3

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를 생성하고 그것을 더 일찍 초기화한다.

+0

당신은 viewDidAppear의 슈퍼 구현을 호출하는 것을 잊었다 작동합니다. –

+0

사실, 그게 이유가 아니었지만. (빨리 쓰고 싶었고 놓쳤습니다.) (Added) – Byte

답변

2

구체적

애니메이션 상수 모두 이전 새로운 부분 열이 슬라이딩되는 방향에 영향을 미친다. 예를 들어 애니메이션 상수 이 UITableViewRowAnimationRight 인 경우 이전 행이 오른쪽 으로 슬라이드 아웃되고 새 셀이 오른쪽에서 슬라이드됩니다.

테이블 뷰가 애니메이션을 통해 멀리 이동하려고하는 동일한 셀을 반환합니다. 이 때문에지도보기가 사라집니다.

그러나, 당신은 단지 사용자에게 경고하지 않고 지정된 섹션 셀의 값을 변경하려는 경우 당신은 당신은 그 세포를 얻을 수 있으며, 직접 설정,

를 해결하기 위해이 부분을 사용하는 것 그들의 새로운 가치. UITableViewRowAnimationNone를 사용

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; 
+0

바로 위에! +1 매우 좋은 쓰기 위해! – Byte

+0

감사합니다 !! 이것에 나의 머리를 긁고있다! – nehz

1

코드가 정상적으로 보이기 때문에 정말 이상합니다. 섹션을 새로 고침하고이 코드를 사용하여 셀을 표시 할 수있었습니다.

[CATransaction begin]; 

[CATransaction setCompletionBlock:^ 
{ 
    [self.tableView reloadData]; 
}]; 

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]  
       withRowAnimation:UITableViewRowAnimationAutomatic]; 

[CATransaction commit]; 

그러나 이것은 수정 사항보다 해결 방법입니다. docs

reloadSections:withRowAnimation: 
Reloads the specified sections using a given animation effect. 

- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation 
Parameters 
sections An index set identifying the sections to reload. 
animation A constant that indicates how the reloading is to be animated, for 

The animation constant affects the direction in which both the old and the new section rows slide. For example, if the animation constant is UITableViewRowAnimationRight, the old rows slide out to the right and the new cells slide in from the right. 
Discussion 
Calling this method causes the table view to ask its data source for new cells for the specified sections. The table view animates the insertion of new cells in as it animates the old cells out. Call this method if you want to alert the user that the values of the designated sections are changing. If, however, you just want to change values in cells of the specified sections without alerting the user, you can get those cells and directly set their new values. 

가입일

+0

reloadSections 및 CATransaction 코드 대신 [self.tableView reloadData]를 사용하십시오. –

+0

둘 다 확실한 해결 방법입니다. 그러나, reloadData를 호출 해, 다른 섹션을 호출 해 차례로 리로드합니다. 이 과정에서 자원이 소모 될 수 있습니다. 귀하의 의견을 보내 주셔서 감사합니다! 하지만 +1 애니메이션. – Byte

관련 문제