今天遇到一个错误调了一下午,终于解决。分享一下问题的始末。
错误:点击UITextView 是程序崩溃。
错误提示:
-[UITextTapRecognizer velocityInView:]: unrecognized selector sent to instance 0x6080003c3a20
错误原因:昨天下午处理 侧滑返回手势 和 scrollView滑动冲突的时候写了一个Category:UIScrollView+Extension。重写了
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer这个方法。
//左边侧滑:解决侧滑返回 与 UIScrollView 冲突
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self];
CGPoint location = [gestureRecognizer locationInView:self];
if (velocity.x > 0.0f&&(int)location.x%(int)[UIScreen mainScreen].bounds.size.width<60) {
return NO;
}
return YES;
}
方法具体如上;
UITextView 继承自 UIScrollView,所以在点击的时候调用了上面的方法,所以崩溃。
解决方法:就是上面的那个方法不能放在Category中了,或者在上面那个方法中加判断。
(ps:一开也没有想到崩溃会是这个原因,后来看到UITextView 继承自 UIScrollView,然后才想起来昨天加的那个方法。看来是一些基础知识不过关啊!)