开发者

Connect a button of a table view cell to the corresponding ViewController

开发者 https://www.devze.com 2023-02-06 16:51 出处:网络
I have a class MyCell.h / MyCell.m which is a subclass of UITableViewCell. In this class I only have four IBOutlet properties, three labels and one button.

I have a class MyCell.h / MyCell.m which is a subclass of UITableViewCell. In this class I only have four IBOutlet properties, three labels and one button.

In the implementation I only have synthesize'd these properties.

Then I have a MyCell.xib which is an UITableViewCell and I connected the elements to the MyCell class properties.

In a MyViewController I put an UITableView in it and the table view cells are styled with the one of MyCell.x开发者_开发知识库ib, also they are conntect, the labels, so I can give them the values of my domain objects, like

cell.myTestLabel.text = myDomainObject.sampleText;

The problem is, that I want to connect the button, so that the MyViewController can handle it and I can get the values of the table view row. How can I do this?

Does anyone know?

Best Regards.


You may setup the action handling manually, take a look on the message addTarget:action:forControlEvents: of your button


You can create a handler in MyCell class and relate it with your button through XIB. This is the only solution. You may additionally create a method in your ViewController class, which will be called from your button's event, from MyCell class.

0

精彩评论

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

关注公众号