是否可以在UITableView的行的一部分中禁用didSelectRowAtIndexPath? [英] Is it possible to disable didSelectRowAtIndexPath in a part of row in UITableView?

查看:89
本文介绍了是否可以在UITableView的行的一部分中禁用didSelectRowAtIndexPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Objective C应用程序中有一个 UITablaView 。我有自定义单元格的标签和 UIImageView 。我想禁用部分行,以便在用户单击此行的部分时禁用 didSelectRowAtIndexPath

I have a UITablaView in my Objective C application. I have the custom cells with a label and a UIImageView. I want to disable a part of the rows, to disable didSelectRowAtIndexPath when users click on this row's part.

我想要这个:

有可能吗?

推荐答案

这是一个简单而优雅的解决方案我可以想一想。

Here is the simple and the most elegant solution that I can think off.

我相信你必须有一个CustomCell,它将IBOutlet保存到左侧的imageView :)你可以使用 hitTest 解决问题的方法:)

I believe you must be having a CustomCell, which holds the IBOutlet to imageView on the left side :) You can make use of hitTest method to solve your problem :)

在你的CustomCell中我们假设它是MyTestCell类写的,

In your CustomCell lets assume it to be MyTestCell class write this,

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if self.myImageView.frame.contains(point) {
            return nil
        }
        return super.hitTest(point, with: event)
    }

其中myImageView是你单元格左侧imageView的IBOulet:)

Where myImageView is the IBOulet of imageView on the left hand side of your cell :)

我正在做的就是检查用户点击的位置,如果触摸点位于单元格框架内,则返回nil作为视图。当你返回nil touch事件时,会停止传播到其父视图,最后永远不会到达单元格因此 didSelectRowAtIndexPath 从未调用过,

All am doing is checking where did user tap, if the touch point is within the frame of cells imageView you return nil as the view. When you return nil touch event stops propagating to its parent views and finally will never reach cell hence didSelectRowAtIndexPath never called,

另一方面,您应该将触摸切换到下一个视图,只需在其超级上调用相同的方法即可完成操作iOS最终会将其追溯到单元格并触发 didSelectRowAtIndexPath

On the other hand you should handover touch to the next view and you do it simply by calling same method on its super iOS will eventually trace it back to cell and triggers didSelectRowAtIndexPath

希望有所帮助:)

这篇关于是否可以在UITableView的行的一部分中禁用didSelectRowAtIndexPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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