Is that possible to use UIPageControl to control the move of UITableView?

前端 未结 1 571
长情又很酷
长情又很酷 2021-01-26 13:49

From Apple sample \"PageControl\" we can know that UIPageControl can be used to control movement of pages in scrollview.

As UITableView is subclass of UIScrollView,I wan

相关标签:
1条回答
  • 2021-01-26 14:31

    It sure is possible, but why would you want this? A table view scrolls vertically, while a page control has a horizontal layout, so it would probably look/feel weird.

    Anyway, if you really want to do this, add your view controller as a target of the page control:

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

    Then implement the scrolling in the action:

    - (void)pageChanged:(UIPageControl *)sender {
        float scrollPosition = ((float)sender.currentPage / (float)sender.numberOfPages) * tableView.contentSize.height;
        [tableView scrollRectToVisible:CGRectMake(0, scrollPosition, 1, 1) animated:YES];
    }
    
    0 讨论(0)
提交回复
热议问题