
@IBOutlet var creeligueBouton: UIbarbuttonItem!
如果条件成立,我想让它消失
if(condition == true){ // Make it disappear} 你真的想隐藏/展示creeligueBouton吗?相反,启用/禁用UIbarbuttonItems要容易得多。您可以使用以下几行来完成此 *** 作: if(condition == true) { creeligueBouton.enabled = false} else { creeligueBouton.enabled = true} 这段代码甚至可以用更短的方式重写:
creeligueBouton.enabled = !creeligueBouton.enabled
让我们在UIVIEwController子类中看到它:
import UIKitclass VIEwController: UIVIEwController { @IBOutlet weak var creeligueBouton: UIbarbuttonItem! @IBAction func hIDe(sender: AnyObject) { creeligueBouton.enabled = !creeligueBouton.enabled }} 如果您真的想显示/隐藏creeligueBouton,可以使用以下代码:
import UIKitclass VIEwController: UIVIEwController { var condition: Bool = true var creeligueBouton: UIbarbuttonItem! //Don't create an IBOutlet @IBAction func hIDe(sender: AnyObject) { if(condition == true) { navigationItem.rightbarbuttonItems = [] condition = false } else { navigationItem.rightbarbuttonItems = [creeligueBouton] condition = true } } overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() creeligueBouton = UIbarbuttonItem(Title: "Creer",style: UIbarbuttonItemStyle.Plain,target: self,action: "creerbuttonMethod") navigationItem.rightbarbuttonItems = [creeligueBouton] } func creerbuttonMethod() { print("Bonjour") }} 总结 以上是内存溢出为你收集整理的使用swift IOS使UIBarButtonItem消失全部内容,希望文章能够帮你解决使用swift IOS使UIBarButtonItem消失所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)