如何在方法中return协议的对象

How to return object of the protocol in the method

我想return方法中的协议对象。有没有更快的方法来实现这一目标?谢谢。

#import "OverlayView.h"

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

@interface ErrorOverlay : UIView
@property (nonatomic, weak) id<ErrorOverlayDelegate> delegate;
@end

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

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

然后将 self 作为参数传递。