大佬教程收集整理的这篇文章主要介绍了iOS协议/代表混淆?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@protocol exampleprot <NSObject> @required -(void) exampledmethod:(NSString *) e1; @end @interface ViewController { __weak id <exampleprot> delegate }
[delegate examplemethod:@"test"]
B.h
@interface test2 : UiViewcontroller <exampleprot>
在B.m实现方法 – (void)exampledmethod:(NSString *)e1;
那么我做错了什么?
班级
@protocol sampleDelegate <NSObject> @required -(NSString *)getDataValue; @end @interface BWindowController : NSWindowController { id<sampleDelegate>delegate; } @property(nonatomic,assign)id<sampleDelegate>delegate; @end
在B.m班
- (void)windowDidLoad { //below only calling the method but it is impelmented in AwindowController class if([[self delegate]respondsToSELEctor:@SELEctor(getDatavalue)]){ NSString *str= [[self delegate]getDataValue]; NSLog(@"Recieved=%@",str); } [super windowDidLoad]; }
在A.h班
@interface AWindowController : NSWindowController<sampleDelegate> //conforming to the protocol
在A.m班
//ImplemenTing the protocol method -(NSString*)getDataValue { NSLog(@"recieved"); return @"recieved"; } //In this method setTing delegate AWindowController to BWindowController -(void)yourmethod { BWindowController *b=[[BWindowController alloc]init]; b.delegate=self; //here setTing the delegate }
以上是大佬教程为你收集整理的iOS协议/代表混淆?全部内容,希望文章能够帮你解决iOS协议/代表混淆?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。