从一个类调用 IBOutlet UIButton 到另一个 Viewcontroller

call IBOutlet UIButton from one class to another Viewcontroller(从一个类调用 IBOutlet UIButton 到另一个 Viewcontroller)
本文介绍了从一个类调用 IBOutlet UIButton 到另一个 Viewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 dataviewcontroller 的视图控制器.另一个名为 scopeviewcontroller

I have one view controller called dataviewcontroller.Another view controller called scopeviewcontroller

dataviewcontroller 我有一个名为 AddDataIBOutletUIButton.我想在我的scopeviewcontroller.我想隐藏那个按钮.

In dataviewcontroller i have an IBOutlet of UIButton called AddData.I want to call this button in my scopeviewcontroller. And I want to hide that button.

我在我的 pager 中使用了这个视图控制器.我想在第三页的 scopeviewcontroller 中隐藏 AddData 按钮.

I have used this view controller in my pager. I want to hide AddData button in my scopeviewcontroller which is present at the third page.

我在 scopeviewcontroller 中的 viewdidload 中尝试了此代码.

I tried this code in viewdidload in my scopeviewcontroller.

但是我得到这个错误:UIViewController"类型的值没有成员AddData"

我在第一个视图控制器中的代码:

my code in first view controller:

class dataviewcontroller: UIViewController {

    @IBOutlet var AddData: UIButton! 
}

我的第二个视图控制器:

class scopeviewcontroller: UIViewController,UITableViewDelegate, UITableViewDataSource {

 override func viewDidLoad() {
        super.viewDidLoad()
let storyboard = UIStoryboard(name: "data", bundle: nil)
       let controller = storyboard.instantiateViewController(withIdentifier: "dataviewcontroller")

        controller.AddData.hidden = true

    }


}

请帮帮我!...谢谢

推荐答案

您无需访问您在寻呼机上添加的每个视图控制器上的按钮.您可以隐藏 scopeviewcontroller 本身的按钮.在 CAPSPageMenuDelegate

You no need to access the button on every view controllers, which you added on the pager. You can hide the button on the scopeviewcontroller itself. with the help of CAPSPageMenuDelegate

在 ScopeViewController 中,设置寻呼机的委托.

In ScopeViewController, set the delegate of your pager.

fun viewDidLoad() {
   super.viewDidLoad()
   pageMenu.delegate = self 
}

并实现协议CAPSPageMenuDelegate

extension scopeviewcontroller: CAPSPageMenuDelegate {
    func willMoveToPage(_ controller: UIViewController, index: Int) {
        self.AddData.isHidden = (index == 2)
    }
}

这篇关于从一个类调用 IBOutlet UIButton 到另一个 Viewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)