【发布时间】:2012-02-24 09:38:05
【问题描述】:
可以从 Block 访问委托属性吗?
@interface TheObject : NSObject
...
@property (nonatomic, assign) id<SomeDelegate> delegate;
@synthesize delegate
- (void) someMethod {
[someObject doSomethingWithCompletionHandler:^(NSArray *)someArray {
[self.delegate otherMethod:someArray];
}];
}
如果委托在调用完成处理程序之前被取消(从也设置委托的对象中的 dealloc 方法)会发生什么?
会不会是内存错误?
我不知道如何将__block 用于属性...
从下面回答:
如果委托是从作为 dealloc 调用的委托的对象中删除的,那么一切都很好。
@property (nonatomic, retain) TheObject theObject;
@synthezise theObject = _theObject;
- (void) thatMethod {
self.theObject = [[TheObject alloc] init] autorelease];
_theObject.delegate = self;
}
- (void) dealloc {
_theObject.delegate = nil;
self.theObject = nil;
}
【问题讨论】:
标签: ios ios4 objective-c-blocks