【发布时间】:2014-11-26 11:20:47
【问题描述】:
我正在我的代码块中寻找保留周期。我的UITableViewController 中有以下代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//[...] Not important code.
__weak ELParkingLocationTVC *weakself = self; // Required? (1)
cell.completionBlock = ^ {
__strong ELParkingLocationTVC *strongSelf = weakself; // Required? (2)
__weak ELParkingLocationTVC *weak2self = weakself; // Required? (3)
[strongSelf dismissViewControllerAnimated:YES completion:^{
__strong ELParkingLocationTVC *strong2self = weak2self; //Required? (4)
ELMenuHistoryTVC *menuTVC = [strong2self.navigationController.viewControllers firstObject];
[menuTVC.parentTabBarController moveToTab:ELMapViewControllerIndex completion:^(BOOL finished) {
ElMainMapViewController *mainMapViewController = menuTVC.parentTabBarController.viewControllers[ELMapViewControllerIndex];
//ELCustomParkplace *customParkplace = [strong2self parkplaceAtIndex:indexPath.row]; //(5)
[mainMapViewController moveToCoordinate:customParkplace.coordinate];
}];
}];
};
}
并有以下问题:
- 我需要哪个
__weak和哪个__strong参考?我确定我必须使用第 1 和第 2,但我真的不确定第 3 和第 4。 - 我可以在这里使用
@strongify和@weakify吗? - 我想我不需要第 (5) 行,但我不确定。
任何建议、链接或好的评论将不胜感激!
【问题讨论】:
-
我已经知道基础知识了,但是感谢您的链接(尤其是
__typeof__(self):-)
标签: ios objective-c iphone objective-c-blocks weak-references