UITableView inside UIScrollView not receiving first tap after scrollling

前端 未结 14 1730
北海茫月
北海茫月 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!

    0 讨论(0)
  • 2020-11-29 05:22

    I have the same problem with nested UITableView and have found a work-around for this:

    innerTableView.scrollEnabled = YES;
    innerTableView.alwaysBounceVertical = NO;
    

    You'll need to set the height of the inner table view to match with the total height of its cells so that it'll not scroll when user scrolling the outer view.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题