UITableView inside UIScrollView not receiving first tap after scrollling

前端 未结 14 1728
北海茫月
北海茫月 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 04:57

    From Apple Documentation, you shouldn't embed a UITableViewinside 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.

    Your problem is really related to what your UIScrollView does.

    But if it's just to hide the tableview when needed (that was my case), you can just move the UITableView in its superview.

    I wrote a small example here : https://github.com/rvirin/SoundCloud/

    0 讨论(0)
  • 2020-11-29 04:57

    I would recommend to look for options like not letting your cell to be in highlighted state when you are actually scrolling the outer scroll view which is very easy to handle and is the recommended way. You can do this just by taking a boolean and toggling it in the below method

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView 
    
    0 讨论(0)
  • 2020-11-29 04:57

    My mistake was implementing the delegate method:

    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
    

    instead of the one I meant to implement:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    

    Hence only being called on the second cell being tapped, because that was when the first cell would be de selected. Stupid mistake made with the help of autocomplete. Just a thought for those of you who may wander here not realizing you've made the same mistake too.

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

    leave the inner UITableView's scrollEnabled property set as YES. this lets the inner UITableView know to handle scroll-related touches on the UIScrollView correctly.

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

    It seems that your UiTableView doesn't recognize your tap. Did you try to use that :

    - (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer
    shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer             *)otherGestureRecognizer
    {
        if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {
            return YES;
        }
        return NO;
    }
    

    Note from apple:

    called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocked by the other. return YES to allow both to recognize simultaneously. the default implementation returns NO (by default no two gestures can be recognized simultaneously)

    note: returning YES is guaranteed to allow simultaneous recognition. returning NO is not guaranteed to prevent simultaneous recognition, as the other gesture's delegate may return YES

    Hope that will help.

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

    That it, if touch table view it will work properly. also with scroll view in same view controller also.

    tableview.scrollEnabled = true;
    
    0 讨论(0)
提交回复
热议问题