gpt4 book ai didi

ios - 未在导航栏内调用 UIButton 选择器

转载 作者:行者123 更新时间:2023-11-28 08:35:59 25 4
gpt4 key购买 nike

我正在尝试将 UIButton 添加到导航栏的中央。

我的导航 Controller 是用标签栏 Controller 初始化的。然后我创建一个带有自定义图像的 UIButton

我的问题是选择器从未被调用,即使我可以看到按钮确实被按下,因为图像动画(按下按钮时)正在播放。

这是我的代码:

let navigationController = UINavigationController(rootViewController: tabBarController)

let image = UIImage(named: "logo")

let but = UIButton(type: .Custom)
navigationController.navigationBar.addSubview(but)
but .setImage(image, forState: .Normal)
but.frame=CGRectMake((self.view.frame.size.width-image!.size.width)/2.0, (navigationController.navigationBar.frame.size.height-image!.size.height)/2.0, image!.size.width, image!.size.height)

but.addTarget(self, action: #selector(self.initTabView), forControlEvents: .AllEvents)
but.addTarget(self, action: #selector(self.initTabView), forControlEvents: .TouchDown)

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window!.rootViewController = navigationController

任何提示将不胜感激。

最佳答案

//尝试这样//类名是 ,在哪个类中存在 initTabView 方法你需要给那个类名

 but.addTarget(self, action: #selector(Classname.initTabView), forControlEvents: .TouchUpInside) 

关于ios - 未在导航栏内调用 UIButton 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37679950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com