2011-05-13 2 views
0

Apple 샘플 "PageControl"에서 UIPageControl을 사용하여 scrollview의 페이지 이동을 제어 할 수 있음을 알 수 있습니다.UITableView의 이동을 제어하기 위해 UIPageControl을 사용할 수 있습니까?

UITableView는 UIScrollView의 하위 클래스이므로 UIPageControl을 사용하여 "PageControl"과 같이 테이블 뷰 셀의 이동을 제어하려고합니다.

하지만 할 수있는 대리인 인터페이스를 찾을 수 없습니다.

질문은 다음과 같습니다

이 가능한이 작업을 수행하기 위해인가요? 그리고 왜 ?

감사

나를 내 질문에 대답하자,

프로그래밍

프로그래밍 방식

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath { 
    NSIndexPath *scrollIndexPath; 
    if (newIndexPath.row + 20 < [timeZoneNames count]) { 
     scrollIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row+20 inSection:newIndexPath.section]; 
    } else { 
     scrollIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row-20 inSection:newIndexPath.section]; 
    } 
    [theTableView selectRowAtIndexPath:scrollIndexPath animated:YES 
         scrollPosition:UITableViewScrollPositionMiddle]; 
} 

답변

2

확실히 가능하다 그것은 행을 선택 6-5 목록 선택 및

스크롤하지만, 왜 이걸 원해? 테이블 뷰는 세로로 스크롤되며, 페이지 컨트롤은 가로 레이아웃을 갖기 때문에 이상하게 보일 것입니다.

- (void)pageChanged:(UIPageControl *)sender { 
    float scrollPosition = ((float)sender.currentPage/(float)sender.numberOfPages) * tableView.contentSize.height; 
    [tableView scrollRectToVisible:CGRectMake(0, scrollPosition, 1, 1) animated:YES]; 
} 
:

[pageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged]; 

그런 다음 동작에서 스크롤을 구현 : 당신이 정말로 이렇게 할 경우

어쨌든, 페이지 제어의 대상으로보기 컨트롤러를 추가

관련 문제