开发者

iPhone - Catching an UIButton touch events from a custom cell

I have a UIButton i开发者_StackOverflownto a custom table view cell and I'd like to target touches into this button to a method WITHOUT adding the event from code but linking into IB. When declaring the touchMethod into the File's owner (custom UITableViewController), the app crashes because of an "unrecognized selector sent to instance". If I declare the touchMethod into the custom UITableViewCell, I cannot link the button to the cell item.

How may I do to catch the Button touch into the custom UITableViewController (custom cell's fil's owner) ?

Please do not post any solution that would conclude adding the method to the button with inline code. I know how to do this.


You should be able to link to the UITableViewCell in IB. (Which I see that you have tried). I assume that you are loading your custom cell from an XIB. If that is the case you may need to go into interface builder and make sure that you have changed the class of the UITableViewCell (in its XIB) to your custom subclass. You can do that in the "Identity Inspector" tab. When your UITableViewCell is selected, at the top of the tab there is a drop-down that probably says "UITableViewCell" change that to your custom subclass. You should then be able to link the button to the correct function in the cell.


Are you sure ,you have set IBOutlet of UITableViewCell.

otherwise just try by setting IBOutlet of UITableViewCell in XIB & changing the class to UITableViewCell from "Identity Inspector".

Tell me if that not work ..


I had a similar problem Oliver and I fixed it by using self as owner when loading the custom cell NIB like so:

[[NSBundle mainBundle] loadNibNamed:@"MyCustomTableViewCell" owner:self options:nil];

just make sure that owner: is set to self. The code above will return an array. Loop over the array until you get an object of type MyCustomTableViewCell

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜