我有一个关于初始化自定义委托的问题。 在MyScrollView initWithFrame方法中,我需要发送委托的第一个位置。但它仍然不为人知,因为我在初始化程序之后在MyCustomView中设置了委托。在init中设置并发送自定义委托方法?
我该如何解决这个问题,所以委托甚至在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;
}
和Darren:非常感谢您为您的快速回复。伟大的社区,伙计们。现在它运作完美。太好了!祝你今天愉快。 – geforce 2012-07-11 19:12:33