2010-01-13 3 views
2

내 UITableView로 아주 간단한 작업을하고 싶습니다. UIActivityIndicatorView를 섹션의 헤더보기에 추가하고 싶을 때마다 애니메이션을 적용하거나 사라지게 만들려고합니다. viewForHeaderInSection :UITableView의 섹션 헤더보기에서 UIActivityIndicatorView에 액세스하는 방법?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 60.0)]; 

// create the title 
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 12.0, 310.0, 22.0)]; 
headerLabel.text = @"some random title here"; 

[customView addSubview:headerLabel]; 
[headerLabel release]; 

// Add a UIActivityIndicatorView in section 1 
if(section == 1) 
{ 
    [activityIndicator startAnimating]; 
    [customView addSubview:activityIndicator]; 
} 

return [customView autorelease]; 

}

activityIndicator 내 컨트롤러 클래스의 속성입니다

내가있는 tableView를 사용하여 헤더보기에 UIActivityIndicatorView를 추가 아무런 문제가 없었다. 내가이있는 viewDidLoad 방법에 ALLOC :

- (void)viewDidLoad 
{ 
(...) 
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(200, 10, 25, 25)]; 
} 

이 방법을 내가 메시지를 보낼 수 있습니다 (-startAnimating 또는 -stopAnimating처럼) 내가 원할 때마다. 문제는 activityIndicator가 tableView를 스크롤하자마자 사라진다는 것입니다 (tableView : viewForHeaderInSection : 메서드가 두 번째로 호출 되었기 때문입니다).

기타 어떻게 그 섹션의 헤더보기에 activityIndicatorView를 추가하고 나중에 메시지를 보낼 수 있습니까? (물론 아래로 스크롤하면 activityIndicator가 사라지지 않습니다.)

대단히 고마워요!

답변

0

여러 활동 영역에서 동일한 활동 표시기를 사용하려고하면 아마 한 위치에서 다른 위치로 이동하게됩니다. 모든 단일 섹션 헤더마다 다른 정보가 필요하다고 생각합니다. MutableArray를 사용하여 생성 한 헤더 뷰를 추적하여 배열에서 슈퍼 뷰가없는 셀을 다시 열거 나 재사용하는 것과 같은 것을 찾을 수 있도록 재사용 할 수 있습니다.

이것은 내가 한 일이 아니기 때문에 추측입니다.하지만 여러 위치에서 동일한보기를 재사용하려고하고 있습니다.

+0

activityIndicator를 여러 위치에 하나씩 갖고 싶지 않습니다. – nmondollot

+0

그게, 서브 뷰를 계속 추가하려고하는 다른 이유를 상상할 수 없기 때문에 당신이하려고했던 것처럼 보입니다. – Nimrod

0

문제는 customView를 다시 만들고 tableView : viewForHeaderInSection :이 호출 될 때마다 activityIndicator를 하위보기로 추가하여 발생하는 것으로 보입니다.

사용하지 파단이 내가 그것을 해결 도움을주었습니다.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 

// Add a UIActivityIndicatorView in section 1 
if(section == 1) 
{ 
    [activityIndicator startAnimating]; 
    return activityIndicator; 
} 

    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 60.0)]; 

// create the title 
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 12.0, 310.0, 22.0)]; 
headerLabel.text = @"some random title here"; 

[customView addSubview:headerLabel]; 
[headerLabel release]; 


return [customView autorelease]; 
} 

(그것이 비록 매우 추한 외모의 activityIndicator 내가 더 나은 거라고 섹션 1의 고유있는 CustomView를 작성하고 추가 섹션의 전체 폭을 소요 activityIndicator를 한 번만 subView로 사용).

관련 문제