如何将UITextView中的触摸传递给UITableViewCell [英] How to pass touch from a UITextView to a UITableViewCell

查看:240
本文介绍了如何将UITextView中的触摸传递给UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  #importScrollableTextView.h

@implementation ScrollableTextView

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

- (void)touchesCancelled:(NSSet *)触及withEvent:(UIEvent *)事件{
if(parentScrollView){
[parentScrollView touchesCancelled:touches withEvent:方法事件];
}
[super touchesCancelled:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)触及withEvent:(UIEvent *)事件{
if(parentScrollView){
[parentScrollView touchesEnded:touches withEvent:方法事件];
}
[super touchesEnded:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)触及withEvent:(UIEvent *)事件{
if(parentScrollView){
[parentScrollView touchesMoved:touches withEvent:方法事件];
}
[super touchesMoved:触及withEvent:event];
}

- (BOOL)canBecomeFirstResponder {
返回YES;
}

@end


解决方案

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

Swift 3: theTextView.isUserInteractionEnabled = false



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


I have a UITextView in a custom UITableViewCell. The textview works properly (scrolls, shows text, etc.) but I need the users to be able to tap the table cell and go to another screen. Right now, if you tap the edges of the table cell (i.e. outside the UItextView) the next view is properly called. But clearly inside the uitextview the touches are being captured and not forwarded to the table cell.

I found a post that talked about subclassing UITextView to forward the touches. I tried that without luck. The implementation is below. I'm wondering if maybe a) the super of my textview isn't the uitableviewcell and thus I need to pass the touch some other way or b) If the super is the uitableviewcell if I need to pass something else? Any help would be much appreciated.

#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

解决方案

Try [theTextView setUserInteractionEnabled:NO]; If the user needs to be able to edit the contents of the TextView, then you might have a design problem here.

Swift 3 : theTextView.isUserInteractionEnabled = false

Storyboard : tick the "User Interaction Enabled" checkbox.

这篇关于如何将UITextView中的触摸传递给UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆