Objective c 如何在方法中返回协议的对象

Objective c 如何在方法中返回协议的对象,objective-c,delegates,protocols,nsobject,Objective C,Delegates,Protocols,Nsobject,我想在方法中返回协议的一个对象。有没有更快的方法来实现这一点?谢谢 #import "OverlayView.h" @protocol ErrorOverlayDelegate <NSObject> - (void)errorOverlayOKButtonAction:(UIButton*)sender; @end @interface ErrorOverlay : UIView @property (nonatomic, weak) id<ErrorOverlayDele

我想在方法中返回协议的一个对象。有没有更快的方法来实现这一点?谢谢

#import "OverlayView.h"

@protocol ErrorOverlayDelegate <NSObject>
- (void)errorOverlayOKButtonAction:(UIButton*)sender;
@end

@interface ErrorOverlay : UIView
@property (nonatomic, weak) id<ErrorOverlayDelegate> delegate;
@end
#导入“OverlayView.h”
@协议错误覆盖Legate
-(void)errorOverlayOKButtonAction:(UIButton*)发送方;
@结束
@接口错误覆盖:UIView
@属性(非原子,弱)id委托;
@结束

只需在方法中再添加一个参数,最好是第一个参数,如下例所示:

- (void)errorOverlay:(ErrorOverlay *)overlay OKButtonAction:(UIButton *)sender;

然后将self作为参数传递。

只需在方法中添加一个参数,最好是第一个参数,如下例所示:

- (void)errorOverlay:(ErrorOverlay *)overlay OKButtonAction:(UIButton *)sender;

然后将
self
作为参数传递。

改为声明
-(void)errorOverlay:(errorOverlay*)overlay ok按钮操作:(UIButton*)发送方。编写
@class-ErrorOverlay并在需要时使用
self
作为
errorOverlay
参数调用该方法?不要将
strong
用于您的委托属性,而是使用
weak
。但它被多次访问@Itachi这就是我使用的原因strong@DicleY你的目标是什么?强/弱表示对象的所有权。改为声明
-(void)errorOverlay:(errorOverlay*)overlay OkbutonAction:(UIButton*)发送方。编写
@class-ErrorOverlay并在需要时使用
self
作为
errorOverlay
参数调用该方法?不要将
strong
用于您的委托属性,而是使用
weak
。但它被多次访问@Itachi这就是我使用的原因strong@DicleY你的目标是什么?强/弱表示对象的所有权。