【发布时间】:2014-03-14 08:30:38
【问题描述】:
我知道...关于这个主题的另一个问题。但我真的不明白。
我的代码:
//MyViewController.h
@property (strong, nonatomic) UIPageViewController *pageViewController;
//MyViewController.m
- (void)setViewControllerForIndex:(NSInteger)index {
[self.pageViewController setViewControllers:_myViewControllers[index]
direction:UIPageViewControllerNavigationDirectionForward
animated:animated
completion:^(BOOL finished){
[self updatedViewControllerTo:index]; //this method is doing a lot of stuff
}];
}
我现在有保留周期吗?
self 正在完成块中被捕获,self 对 pageViewController 有很强的引用,所以间接我有一个保留周期?
我必须使用__weak MyViewController *weakSelf 语句并在完成块中使用weakSelf 吗?
或者:即使我有一个保留周期,这有关系吗?当 block 完成时,block 中的所有对象都会被释放,所以保留循环(或对 self 的强引用)也会被释放?
updatedViewControllerTo: 方法也在进行 UI 更改。所以必须调用该方法。当我使用weakSelf时,我必须在块中创建self 的强引用吗? (参考http://masteringios.com/blog/2014/03/06/avoid-strong-reference-cycles/ 的最后一个代码块)。
【问题讨论】:
标签: ios objective-c