iOS delegate and block

Source: Internet
Author: User

//protocol definitions for delegates@protocolUpdatedelegate <nsobject>-(void) Update;@end@interfaceTest:nsobject//delegate Variable definition@property (nonatomic, weak)ID<UpdateDelegate>Delegate;//Blocktypedefvoid(^updateblock) (IDobj); @property (nonatomic, copy) Updateblock Updateblock;- (void) Starttest; @end@implementationTest- (void) starttest{[Nstimer scheduledtimerwithtimeinterval:3.0ftarget:self selector: @selector (scheduledend) Userinfo:nil repeats:no];}- (void) scheduledend{[self.DelegateUPDATE];//Delegate//Block    if(Self.updateblock) {Self.updateblock (@"Test"); }}@end//Implement- (void) viewdidload{[Super Viewdidload]; Test*test =[[Test alloc] init]; Test.Delegate= self;//set up a delegate instance//Implement blockTest.updateblock = ^ (IDobj) {Uialertview*alert=[[uialertview Alloc] Initwithtitle:@"Tips"Message:objDelegate: Self Cancelbuttontitle:nil otherbuttontitles:@"Determine", nil]; Alert.alertviewstyle=Uialertviewstyledefault;    [Alert show];        }; [Test starttest];//Start Timer}//The delegate object implements the method of the protocol declaration, which is called by the delegate object- (void) update{Uialertview*alert=[[uialertview Alloc] Initwithtitle:@"Tips"Message@"Time to" Delegate: Self Cancelbuttontitle:nil otherbuttontitles:@"Determine", nil]; Alert.alertviewstyle=Uialertviewstyledefault; [Alert show];}

iOS delegate and block

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.