Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a UITableViewCell but still have interactions with accessory views (i.e UISwitch)

Is there a way that I can disable a UITableViewCell from triggering the didSelectCellAtIndexPath: delegate, while still retaining the ability to use a UISwitch that is in the accessory view of that cell.

I know you can set cell.userInteractionEnabled = NO, this will disable the cell but is also prevents me from using the switch in the accessory view. I know I could also try to detect what cell was tapped in the didSelectCellAtIndexPath: method but since my table view is dynamic and changes depending on what the user is doing that could get messy.

I'm looking for a simple and elegant solution that I could use. Any ideas?

like image 744
Christian Gossain Avatar asked Jun 22 '13 19:06

Christian Gossain


1 Answers

if you do not wan't to use cell.userInteractionEnabled = NO then you set cell.selectionStyle = UITableViewCellSelectionStyleNone

and let your cell trigger didSelectRowAtIndexPath.

Now here in this method "didSelectRowAtIndexPath" you have to avoid / ignore selection , by comparing object type from your datasource array at that particular index.

like image 66
Muhammad Idris Avatar answered Oct 31 '22 18:10

Muhammad Idris