问题
Issue: I keep getting EXC_BAD_ACCESS. And after I open NSZombieEnabled, I saw this [FeatureCommentListViewController respondsToSelector:]: message sent to deallocated instance 0x7c1dc30
Before I changed my project to ARC, there is no such error, but after I changed to ARC, this error appeared.
I declare a ViewController in a Block and push it into navigation Controller. Will this reason case it's lifetime shorter?
UIBlockButton is from this post
UIBlockButton *lbGood3 = [[UIBlockButton alloc] initWithFrame:CGRectMake(0, 0, First_Button_Width, [self getGoodRow2Height:productDetail]) ]; [lbGood3 handleControlEvent:UIControlEventTouchUpInside withBlock:^ { NSLog(@"%@", Label.text); ProductDetail *productDetail = [productDetailDict objectForKey:@"product"]; NSString *dp_id = [NSString stringWithFormat:@"%@-%@",productDetail.url_crc,productDetail.site_id]; FeatureCommentListViewController *cmtListController = [[FeatureCommentListViewController alloc] initWithNibName:@"FeatureCommentListViewController" bundle:nil]; cmtListController.title = Label.text; cmtListController.isReviewed=isReviewed; cmtListController.productDetail=productDetail; cmtListController.dp_id=dp_id; cmtListController.feature_name = @"&feature_good_id=2"; [self.navigationController pushViewController:cmtListController animated:YES]; }];
Should I declare the controller as a member of this viewController or just declare out of the block?
回答1:
I solved this by alloc the FeatureCommentListViewController in the viewDidLoad function and use it in block.
回答2:
1st. Im wondering why do you push a view controller in a block but not in the main thread? Isn't it important to give a quick response to the touch action?
2nd.[self.navigationController pushViewController:cmtListController animated:YES];
is in your block. Whenever you left the current navigationController
what will the self.navigationController
represent?
3rd. If you declare the viewController
out of the block you can add __block
in front of it as mentioned by Hermann Klecker.
来源:https://stackoverflow.com/questions/11449734/under-arc-keep-getting-exc-bad-access-after-using-arc-because-of-using-block