2013-07-28 2 views
0

내 scrollview에 포함 된 그림이 테이블 뷰를 위아래로 스크롤 할 때까지 표시되지 않지만 내 tableview의 각 셀 안에 scrollview가 있습니다 ... 나는 scrollview 및 셀에 대한 @property. cellForRowAtIndexPath : 메서드에서 scrollview를 설정하는 코드가 있습니다. 이것은 초기 생성시 호출되어야합니다. 나는 혼란 스럽다.UITableView의 UIScrollView 내용 문제

문제를 제거하고 앱을 시작할 때 처음에 이미지가 나타나게하려면 어떻게해야합니까?

관련 코드 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellID = @"CustomID"; 

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 

    if (cell == nil) { 
     cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 
    } 

    for (int i = 0; i < [imageArray count]; i++) { 
     CGRect frame; 
     frame.origin.x = cell.scrollView.frame.size.width * i; 
     frame.origin.y = 0; 
     frame.size = cell.scrollView.frame.size; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; 
     imageView.image = [UIImage imageNamed:[imageArray objectAtIndex:i]]; 
     [cell.scrollView addSubview:imageView]; 
    } 

    cell.scrollView.contentSize = CGSizeMake(cell.scrollView.frame.size.width * [imageArray count], cell.scrollView.frame.size.height); 

    return cell; 
} 
+0

죄송합니다. 무엇이 문제입니까? –

+0

스크롤보기를 어디에서 인스턴스화합니까? IB/Storyboard Editor에서 'CustomCell'을 디자인 했습니까? –

+0

셀의 기본 크기는 무엇이며 스크롤 뷰는 'CGRectZero'와 같은 프레임입니까? – Wain

답변

1

이 정확하게 질문에 관련되지 않고, 너무이 문제로 실행됩니다 :

당신의 세포가 재사용 될 것이라는 점을 잊지 마십시오. reusage시 (셀이 화면 밖으로 위쪽으로 이동하고 하단에 나타나는 다음 그냥 disappeard 및 재사용 된 CustomCell의 물리적 인스턴스 것, 아래로 사용자가 스크롤 말할 수 있습니다.)

따라서 추가

for (UIView *aView in [NSArray arrayWithArray:cell.subviews]) { 
     [aView removeFromSuperview]; 
     // if you don't arc then release them and take care of their subviews - if any. 
    } 

새 UIImageView를 추가하기 전에. (한 가지 방법으로 모든 하위 뷰를 제거하는 방법이 있다고 생각했지만 찾지 못했습니다)

+0

이 경우, 나는 그가'cell.scrollView.subviews'에서 서브 뷰를 제거해야한다고 생각합니다. UIScrollView에서 모든 하위 뷰를 제거하면 스크롤 인디케이터도 제거된다는 점에주의하십시오. 스크롤 뷰에서 콘텐츠 만 삭제할 수 있도록 일종의 수표 (태그 또는 클래스 기반)를 수행해야합니다. –