问题描述
我有一个名为 dataviewcontroller
的视图控制器.另一个名为 scopeviewcontroller
I have one view controller called dataviewcontroller
.Another view controller called scopeviewcontroller
在 dataviewcontroller
我有一个名为 AddData
的 IBOutlet
的 UIButton
.我想在我的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!