1
내 코드에서 내 블록의 유지 사이클을 찾고 있습니다. 내 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)이 필요 없다고 생각하지만 잘 모르겠습니다.
어떤 제안, 링크 또는 좋은 의견을 주시면 감사하겠습니다!
이 기사를 시도하십시오 http://dhoerl.wordpress.com/2013/04/23/i-finally-figured-out-weakself-and-strongself/ – l0gg3r
저는 기본 사항을 이미 알고 있지만 링크 (특히' __typeof __ (self)':-) – Szu