我有一个UITextView在自定义的UITableViewCell中。 UITextView可以正常使用(滚动、显示文本等),但我需要用户能够点击单元格并跳转到另一个屏幕。现在,如果您点击表格单元格的边缘(即UITextView之外),下一个视图会被正确调用。但显然,在UITextView内部,触摸事件被捕获并且无法转发到单元格。
我找到了一篇关于子类化UITextView以转发触摸事件的帖子。我尝试过但没有成功。实现如下。我在想可能是a)我的textview的super并不是uitableviewcell,因此我需要通过其他方式传递触摸事件;或者b)如果super是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