简体   繁体   中英

How to stop the View Controller to get the touch of a tableView cell's subview?

I have a TableView in my ViewController. In the selected state, its cell's subview increases in width and comes outside it's bounds.

When I tap on this subview, touches are going to the View Controller's implementation of touchesBegan which is being used deselect the cell.

Now this subview is not being clipped and being allowed to go out, so Ideally the touches falling on it, should go to it but why are they going to the ViewController having the tableview ?

  • TableView is on left of the iPad screen (the View Controller) as a sidebar.
  • Selected cell comes out like a drawer as shown below.
  • on tapping anywhere else in the screen, the drawer(selected cell) goes back in.

The problem is the region in the selected cell, which goes outside the tableview's bounds, If clicked, gives the touches to touchesBegan method in the ViewController.

Thus it ends up going back in.

=================================================
======                                           =
======                                           =
======                                           =
=============                                    =
=============                                    =
======                                           =
======                                           =
======                                           =
======                                           =
======                                           =
======                                           =
======                                           =
======                                           =
==================================================

Yes, this will happen because the updated cell is now exceed the tableview's width, so now obviously touches will go to the supperview of tableview. If you want to disallow that touch then you need to increase the width of your tableview as well, so cell view will comes under table and then you will receive the touches on tableview.

Actually there is one property of UIView called "clipsToBounds" and by default its value is "No" so this will not clipped the area which is outside the UIView and that's why you seeing the cell view but didn't get the touches and this will apply for all type of views.

Hope this will help you :)

I think instead of taking view controller try to create custom views one for table view and the other is your view which will be displayed like a drawer. create custom delegate for the tableview. applied functionality with animation like push and pop view controllers.I think this could be help you very well. set tableviewcell selection style property to none.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM