Monday, September 30, 2013

iOS 7 ( XCode 5) Tutorial - IBAction is not working with custom cell

iOS 7 ( XCode 5) IBAction is not working with custom cell


Many of the developer used custom view to show custom cell on Table view for older version of iOS. If you are one of them, then you will have to face a problem that your button click action will no longer work with iOS7.


How to resolve this:

You have three options:

Option 1:  Create the new lay out with new table cell instead of taking view. and put all layouts again in table cell.

I know, this will require a lot of effort. If you don't want to do this, we have a very small hack for it : option 2


Option 2: Create a IBOutlet for your button and add this button as a subview of your cell's content view.


    [self.myCell.contentView addSubview:self.btn_click];


The above line of code will add btn_click as a subview of you content view. Now button click action should work.

Option 3: 

The best way : 

i) Take An outlet UITableViewCell.
ii) Make existing view as subview of new table cell.
iii) Disconnect the connection of custom cell to existing view and connect it to new UITableViewCell.

thats it, Your IBAction will work now.

May be you got the crash with error message that "class is not key value coding - compliant.". Check your old view connection and remove all connection having yellow mark.

Please don't hesitate to use comment section if you have any question.