iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UIButton永远不会在Action中触发代码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下屏幕:

ios – UIButton永远不会在Action中触发代码

x是UIButton的图像,我已经为按钮添加相应的操作.然而,当我点击按钮时,它永远不会触发动作中的代码.

这是一些代码

@IBACtion func CloseProfilePage(sender: AnyObject) {
        self.removeAnimate();    
    }

这是用于启动视图控制器的代码

func collectionView(collectionView: UICollectionView,didSELEctItemATindexPath indexPath: NSIndexPath) {
        let SELEctedAppointment = self.dayDatasource!.appointmentATindex(indexPath.item);
        let profilePageViewController = ProfilePageViewController.init(withAppointment: SELEctedAppointment);

        profilePageViewController.view.frame = self.view.frame
        self.view.addSubview(profilePageViewController.view)
        profilePageViewController.didMoveToParentViewController(self)

    }

该按钮肯定在xib中连接到动作:

ios – UIButton永远不会在Action中触发代码

当我检查视图层次结构时,按钮顶部没有任何其他内容可以阻止按钮但是会记录点击次数.我在这里假设UIButton中的imageView是可点击的,因为它是按钮的一部分.

ios – UIButton永远不会在Action中触发代码

图像中的X不是我添加的图像视图,它是UIButton附带的图像视图.话如此,我还采取了以下措施:

self.profilePageClosePopUpButton.imageView?.userInteractionEnabled = true;

按钮仍然无法点击.我哪里错了?

解决方法

我很难说这个,但我只是在这里一个解决方案,以防将来有人遇到同样的问题,也许这篇文章可以帮助他们.

在视图中,如下图所示,我在界面构建器中有一些无意中关闭了User Interaction Enabled.因为这是关闭的,所有其他孩子都没有启用交互,因此按钮不可点击的原因…

ios – UIButton永远不会在Action中触发代码

故事的道德是,检查您的父视图并确保其用户交互也已启用.

大佬总结

以上是大佬教程为你收集整理的ios – UIButton永远不会在Action中触发代码全部内容,希望文章能够帮你解决ios – UIButton永远不会在Action中触发代码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。