如何将UITextView中的触摸传递给UITableViewCell

Mar*_*tin 14 iphone uitableview uitextview

我在自定义UITableViewCell中有一个UITextView.textview工作正常(滚动,显示文本等),但我需要用户能够点击表格单元格并转到另一个屏幕.现在,如果您点击表格单元格的边缘(即在UItextView之外),则会正确调用下一个视图.但是在uitextview中显然正在捕获触摸而不是转发到表格单元格.

我发现了一篇帖子,谈到了将UITextView子类化以转发触摸.我没试过就试过了.实施如下.我想知道是否可能a)我的textview的超级不是uitableviewcell因此我需要通过其他方式传递触摸或b)如果超级是uitableviewcell,如果我需要传递其他东西?任何帮助将非常感激.

#import "ScrollableTextView.h"

@implementation ScrollableTextView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (parentScrollView) {
        [parentScrollView touchesBegan:touches withEvent:event];
    }
    [super touchesBegan:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    if (parentScrollView) {
        [parentScrollView touchesCancelled:touches withEvent:event];
    }
    [super touchesCancelled:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (parentScrollView) {
        [parentScrollView touchesEnded:touches withEvent:event];
    }
    [super touchesEnded:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if (parentScrollView) {
        [parentScrollView touchesMoved:touches withEvent:event];
    }
    [super touchesMoved:touches withEvent:event];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

@end
Run Code Online (Sandbox Code Playgroud)

gre*_*reg 33

尝试[theTextView setUserInteractionEnabled:NO]; 如果用户需要能够编辑TextView的内容,那么您可能会遇到设计问题.

斯威夫特3: theTextView.isUserInteractionEnabled = false

故事板:勾选"启用用户交互"复选框.

  • 我遇到的问题是我希望用户能够触摸一个电话号码,但我还需要进行调整.我仍然在寻找两种方法.如果有人有任何建议,请告诉我.如果我发现我会在这里发布. (4认同)
  • 非常感谢!顺便说一句,如果有人更喜欢在Interface Builder中设置它:在检查器中打开UITextView的属性窗格,滚动到"视图"窗格所在的底部,并取消选中"启用用户交互". (3认同)