我想用一个可选的委托方法扩展UIAlertViewDelegate协议。UIAlertViewDelegate扩展协议
接口
@protocol HPAlertViewDelegate;
@interface HPAlertView : UIAlertView<UIWebViewDelegate>{
id <HPAlertViewDelegate> delegate;
UIWebView *webView;
}
@property (nonatomic, assign) id <HPAlertViewDelegate> delegate;
@property (nonatomic, retain) UIWebView *webView;
- (id)initWithWebURL:(NSString *)url title:(NSString *)aTitle;
@end
@protocol HPAlertViewDelegate <UIAlertViewDelegate>
@optional
- (void)HPAlertViewWebViewDidLoad:(HPAlertView *)alertView;
@end
实施
@dynamic delegate
当我使用它在myViewController像:
HPAlertView *alertView = [[HPAlertView alloc] initWithWebURL:myURL tile:myTitle];
[alertView setDelegate:self];
我有2个问题:
如果我委托设为@dynamic,我在HPAlertView委托总是空,即使setDelegate:自
如果我委托设为@synthesize,我代表响应仅适用于新的@optional委托方法,而不适用于UIAlertView委托方法。
我知道这不是你要求的,但你不应该真的继承'UIAlertView'。 – hypercrypt