Getting EXC_BAD_ACCESS when trying to call [UITableView panGestureRecognizer]

自作多情 提交于 2019-12-11 18:34:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!