- (void) AddTarget: (ID) Target action: (SEL) Action forcontrolevents: (uicontrolevents) controlevents; The method is unable to pass the parameter, can get only the UIButton of the response. Let's learn how to "pass parameters" through UIButton. We use UITableView as an example to define a cell in UITableViewCell, which we call a UIButton control on Customcell,cell. What we're going to do is get the cell when we click UIButton. This can be done in two ways. 1. Using delegate first, define protocol in the Customcell class file, as defined below@protocolCustomcellprotocol- (void) Customcell: (Customcell *) cell Didtapbutton: (UIButton *) button;@endAdd the UIButton response to the Customcell file, for example, this response is called-(Ibaction) Buttontarget: (ID) sender; This method is called when the button is clicked. This method can be implemented as follows,-(Ibaction) Buttontarget: (ID) sender{if([Self.Delegaterespondstoselector: @selector (Customcell:didtapbutton:)]) {[Self.Delegateperformselector: @selector (Customcell:didtapbutton:) withobject:self WithObject:self.button]; }} Then implement the Proxy method in Uiviewcontroller, so that you can get the UITableViewCell of the UIButton. 2When you add a response to the second method in Viewcontroller-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath; Add a response directly to the UIButton method. Implemented as follows,-(UITableViewCell *) TableView: (UITableView *) Atableview Cellforrowatindexpath: (Nsindexpath *) indexpath{Customcell*cell = [Atableview dequeuereusablecellwithidentifier:@"Customcell"]; [Cell.button addtarget:self Action: @selector (Didtapbutton:) forcontrolevents:uicontroleventtouchupinside];returnCell;} Then when you click on the button, it will be called- (void) Didtapbutton: (UIButton *The rest of sender is how to get the cell it's in by this sender. The way we do this,- (void) Didtapbutton: (UIButton *) sender{CGRect buttonrect=Sender.frame; for(Customcell *cellinch[TableView Visiblecells]) { if(Cgrectintersectsrect (Buttonrect, Cell.frame)) {//cell is what you get. } }}
Ios--uibutton Response Pass Parameters