Issue with row selection UITableView inside UIScrollView

泪湿孤枕 提交于 2019-12-11 12:25:52

问题


I have a view controller with following layout:

  • Container View
    • UIScrollView
      • UITableView as a sub view of a UIScrollView

I have another UITableViewController in which I have a few rows and some methods when the row gets selected. Now I want to display this UITableview inside the UIScrollView. So I add the UITableView as a subview of UIScrollView. The table is displayed in the scroll view just fine, but when I tap in the scroll view to select the table's row, then row is being highlighted but the method is not getting called when the row is selected..

    PBDashboardPickupTable *dashtable = [[PBDashboardPickupTable alloc]initWithNibName:@"PBDashboardPickupTable" bundle:nil];
    [self.scrollView addSubview:dashtable.tableView];

Also I have set scroll view's delayContentTouches to YES and cancelContentTouch to NO from Interface Builder. Also userInteractionEnabled is set to YES... then why is the method not getting called when I tap the table view's row?


回答1:


Apple specifically warns in the documentation to avoid putting a UITableView inside of a UIScrollView:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

Since UITableView inherits from UIScrollView, I would suggest you add any additional views you need as a tableHeaderView, tableFooterView, or as custom cells in the table.



来源:https://stackoverflow.com/questions/15127525/issue-with-row-selection-uitableview-inside-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!