获取按钮操作:UICollectionView Cell [英] Getting button action : UICollectionView Cell

查看:233
本文介绍了获取按钮操作:UICollectionView Cell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过nib创建了一个 UICollectionViewCell 并在其中添加了一个按钮并创建了一个.h和.m文件,将该类添加到了nibs 文件的所有者。然后在.m中写了一个按钮动作,通过插座连接它。

I have created a UICollectionViewCell by nib and added a button inside it and created a .h and .m files added the class to the nibs file's owner.then wrote a button action in the .m connected it via outlet.

集合视图填充正常,但无法获得引爆了一次行动。
我认为收集单元格的代表被调用。

The collection view is populating fine ,but cannot get the buton action triggered. I think the delegate for collection cell is called.

我如何获得按钮操作?

推荐答案

我也有这个问题。没有子视图会收到触摸事件。虽然Scott K的解决方法确实有效,但我仍然觉得有些不对劲。所以我再看看我的笔尖,并注意到我用来创建UICollectionViewCell的原始子视图是一个UIView。即使我将类更改为UICollectionViewCell的子类,XCode仍然认为它是UIView,因此您看到contentView没有捕获触摸事件的问题。

I had this problem as well. No subviews would receive touch events. While Scott K's workaround does work, I still felt something was wrong. So I took another look at my nib, and noticed that the original subview I used to create a UICollectionViewCell was a UIView. Even though I changed the class to a subclass of UICollectionViewCell, XCode still considered it a UIView, and hence the issues you see with contentView not catching touch events.

要修复此问题,我通过确保拖动UICollectionViewCell对象并将所有子视图移动到那个来重新编写nib。之后,触摸事件开始对我的单元格的子视图起作用。

To fix this, I redid the nib by making sure to drag a UICollectionViewCell object, and moving all the subviews to that. Afterwards, touch events began to work on my cell's subviews.

可以指示您的笔尖是否配置为UICollectionViewCell,请查看高级视图的图标。

Could indicator to see if your nib is configured as a UICollectionViewCell is look at the icon for your high level view.

如果它看起来不像这样,那么它可能会错误地解释触摸事件。

If it doesn't look like this, then its probably going to interpret touch events wrong.

这篇关于获取按钮操作:UICollectionView Cell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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