UITableView inside UIScrollView not receiving first tap after scrollling

前端 未结 14 1831
北海茫月
北海茫月 2020-11-29 04:31

Brief

I am having an issue with a UITableView inside a UIScrollView. When I scroll the external scrollView, the table<

14条回答
  •  难免孤独
    2020-11-29 05:21

    As other answers say you shouldn't put a tableview in a scrollview. A UITableView inherits from UIScrollView anyway so I guess that's where things get confusing. What I always do in this situation is:

    1) Subclass UITableViewController and include a property UIView *headView.

    2) In the parent UIViewController create all the top stuff in a container UIView

    3) Initialise your custom UITableView and add the tableView's view to the view controller full size

    [self.view addSubview: self.myTableView.view];
    

    4) Set the headView to be your UIView gubbins

    self.tableView.headView = myHeadViewGubbins.
    

    5) In the tableViewController method

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

    Do:

    if ( section == 0 ) {
        return self.headView;
    }
    

    Now you have a table view with a bunch of other shizzle at the top.

    Enjoy!

提交回复
热议问题