我有一个关于初始化自定义委托的问题。在 MyScrollView initWithFrame 方法中,有我需要发送我的委托的第一个位置。但是那里仍然未知,因为我在初始化程序之后在 MyCustomView 中设置了委托。
我该如何解决这个问题,所以即使在 init 中也会调用委托?谢谢你的帮助..
MyCustomView.m
self.photoView = [[MyScrollView alloc] initWithFrame:frame withDictionary:mediaContentDict];
self.photoView.delegate = self;
//....
MyScrollView.h
@protocol MyScrollViewDelegate
-(void) methodName:(NSString*)text;
@end
@interface MyScrollView : UIView{
//...
__unsafe_unretained id <MyScrollViewDelegate> delegate;
}
@property(unsafe_unretained) id <MyScrollViewDelegate> delegate;
MyScrollView.m
-(id) initWithFrame:(CGRect)frame withDictionary:(NSDictionary*)dictionary{
self.content = [[Content alloc] initWithDictionary:dictionary];
self = [super initWithFrame:frame];
if (self) {
//.... other stuff
// currently don´t get called
[self.delegate methodName:@"Test delegate"];
}
return self;
}