【问题标题】:how to get position of UITextView in UITableView [duplicate]如何在 UITableView 中获取 UITextView 的位置 [重复]
【发布时间】:2012-12-03 06:09:14
【问题描述】:

可能重复:
UITableView and keyboard scrolling issue

有一个UIView,其中我有它的子视图UITableView,在UITableViewCells 我有UITextView,用户可以在其中输入文本,现在我想获得POSITION用户当前点击的那个 UITextView。

UIToucheBegan 不调用 UIView子视图 意味着来自UITableView。

【问题讨论】:

标签: objective-c ios uitableview uitouch


【解决方案1】:

子类 UITableView,然后在该子类中实现 touchesBegan,如果你想触摸 tableview

【讨论】:

    【解决方案2】:

    尝试在 cellForRowAtIndexPath 方法中的 textField 中添加标签

    然后在用户开始输入 UITextField 时调用的方法中查找 sender.tag

    或者...可能为此制作 CustomCell 会更好

    【讨论】:

      【解决方案3】:

      你可以做的是:

      1. 将您的视图控制器设置为 UITextView 委托。
      2. 开始编辑时,循环遍历 UITextView 超级视图,直到找到 UITableViewCell。
      3. 使用 UITableViewCell 框架属性来确定它的位置(结合 UITableView.contentOffset、UITableView.frame 和你的主容器 UIView.frame)来获取 UITextView 相对于 UIView(或任何你想要的视图)的位置。

      1. 向 UITableView 添加点击手势识别器。
      2. 在目标方法中,使用[tapGestureRecognizer locationInView:myTableView] 获取与UITableView 内容相关的点击。
      3. 使用 UITableView indexPathForRowAtPoint: 方法,然后使用 cellForRowAtIndexPath: 来获取 UITableViewCell。从那里,执行上述 (3)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        • 2012-10-26
        • 2013-07-18
        • 2013-07-09
        • 1970-01-01
        相关资源
        最近更新 更多