1. The following code is a description: When you click on the toolbar button, notify the agent to adjust the proxy method.
1- (void) DIDCLICKEDTOOLBARBTN: (UIButton *) button2 {3 4 if([Self.Delegaterespondstoselector: @selector (Toolbar:didclickedbutton:)]) {5[Self.Delegatetoolbar:self DidClickedButton:button.tag];6 }7self.selectButton.selected =NO;8button.selected =YES;9Self.selectbutton =button;Ten One}2. Unfortunately, at this time delegate has not been specified, that is to say Delegate=nil, the specific scenario is as follows:
1> assumes that there is a controller that instantiates Toolbar in the controller's Viewdidload method, which is called [[Toolbar alloc] init]. toolbar.delegate = self after init execution.
2> adds toolbar 4 buttons to the Init method of toolbar, [self addtoolbarbuttonwithtitle:@ "xxx" Andtag: enum type].
3> requires the default click on the 1th button, by the way, when the button is created, verify the number of Toolbar.subview, when the number is 1 o'clock, execute [self Didclickedtoolbarbtn:button]
1- (void) Addtoolbarbuttonwithtitle: (NSString *) title Andtag: (qktoolbarbuttontype) Toolbarbuttontype2 {3Qktoolbarbutton *button =[[Qktoolbarbutton alloc]init];4Button.tag =Toolbarbuttontype;5 6 [button Settitle:title forstate:uicontrolstatenormal];7 8 [button addtarget:self action: @selector (DIDCLICKEDTOOLBARBTN:) Forcontrolevents:uicontroleventtouchdown];9 Ten [self Addsubview:button]; One A if(Self.subviews.count = =1) { - [self Didclickedtoolbarbtn:button]; - } the}3. For the Delegate=nil problem described above, the following workaround can be used to adjust the corresponding method in the agent's Set method
1 -(void) Setdelegate: (ID<QKToolbarDelegate>)delegate2{ 3 delegate; 4 Qktoolbarbutton *toolbarbtn = (Qktoolbarbutton *) [self viewwithtag:qktoolbarbuttontypedefault]; 5 [self didclickedtoolbarbtn:toolbarbtn]; 6 7 }
Workaround for agent Nil when IOS notifies agent how to perform proxy