Workaround for agent Nil when IOS notifies agent how to perform proxy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.