问题
Just upgraded xCode to 4.5. iOS 5 is still my deployment target, but Base SDK is now 6.0.
Application now crashes where previously it did not. The project uses ARC.
The offending line is a property call on a UITableView... asking for the panGestureRecognizer (line 3 below).
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIPanGestureRecognizer* pgr = [imageTableView panGestureRecognizer];
[pgr setMinimumNumberOfTouches:2];
[pgr setMaximumNumberOfTouches:2];
}
Produces the following error message:
-[UIScrollViewPanGestureRecognizer retain]: message sent to deallocated instance 0x1ea38f70
How is this possible? Zombie Analysis says that the gestureRecognizer has been released already?!
回答1:
Turns out this was an ARC issue... two different solutions for those interested.
@autoreleasepool {
UIPanGestureRecognizer* pgr = [imageTableView panGestureRecognizer];
[pgr setMinimumNumberOfTouches:2];
[pgr setMaximumNumberOfTouches:2];
}
Or
[imageTableView.panGestureRecognizer setMinimumNumberOfTouches:2];
[imageTableView.panGestureRecognizer setMaximumNumberOfTouches:2];
Lesson learned, if it can't be possible.... try ARC as the culprit.
来源:https://stackoverflow.com/questions/12569560/getting-exc-bad-access-when-trying-to-call-uitableview-pangesturerecognizer