【问题标题】:how to get UItableviewcell from cgpoint?如何从 cgpoint 获取 UItableviewcell?
【发布时间】:2014-08-23 20:44:21
【问题描述】:

我正在编写一个需要将按钮从 UIView 拖动到 UItableview 的应用程序,并且根据用户离开的位置,我需要知道用户离开了哪个 tableview 单元格。

这是必需的,因为我需要根据用户离开的 tableviewcell 更新该特定单元格中的内容。

任何帮助将不胜感激。

【问题讨论】:

    标签: objective-c xcode uitableview uipangesturerecognizer


    【解决方案1】:

    或者你可以使用 UITableView 实例方法

    - (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
    

    它返回你的索引路径,然后你可以使用方法获取你的单元格实例

    - (__kindof UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
    

    【讨论】:

      【解决方案2】:

      您可以使用 UITableView 的 rectFor[whatever] 方法来确定您的点与哪个单元格相交。

      例如,您可以使用以下命令迭代可见的索引路径:

      - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath
      

      并检查与 CGRectContainsPoint() 函数的交集。

      【讨论】:

        猜你喜欢
        • 2015-01-06
        • 1970-01-01
        • 2012-05-20
        • 2013-03-20
        • 2012-10-11
        • 1970-01-01
        • 2015-08-14
        • 1970-01-01
        • 2013-03-20
        相关资源
        最近更新 更多