首页 文章

在UITableViewCell内滚动UITextView

提问于
浏览
0

我有一个UITextView到UITableViewCell,但我无法滚动文本 . 当我尝试滚动textView时,tableView grab 了触摸 .

有什么方法可以解决这个问题吗?

PS:UITableViewController的子类

1 回答

  • 1

    我想你可以检测到被触摸的对象,如果它是UITextView,那么暂时禁用UITableView滚动:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
         [super touchesBegan:touches withEvent:event];
         UITouch *touch = [touches anyObject];
    
         //detect if touch is on UITextView
         if ([touch.view isKindOfClass: UITextView.class]) {
             yourTableView.scrollEnabled = NO;
         }
    }
    

    不要忘记在touchesEnded中重新启用UITableView的滚动

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
            yourTableView.scrollEnabled = YES;
    }
    

相关问题