I have one view controller called dataviewcontroller
.Another view controller called 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.
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.
I tried this code in viewdidload
in my scopeviewcontroller
.
But is m getting this error: Value of type 'UIViewController' has no member 'AddData'
my code in first view controller:
class dataviewcontroller: UIViewController {
@IBOutlet var AddData: UIButton!
}
my second view controller:
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
}
}
Please help me out!...Thanks
An outlet doesn't instantiate because an outlet is a variable (or property).
The objects in a nib are instantiated when that nib is loaded, and they are assigned to each outlet as immediately as possible afterward, after the objects are created but before awakeFromNib is sent to all relevant objects.
Check ans by Peter Hosey here for detailed explanation.
In your case you can pass a
bool
var fromscopeviewcontroller
todataviewcontroller
. Based on conditions you can set yourAddData
button hidden property true or false indataviewcontroller
'sviewDidLoad
orviewDidAppear
.You have to Type Cast the
dataviewcontroller
fromUIViewController
because by default it will return to the parent classUIViewController
object that doesn't have theAddData
button, You have to do just like that:-NOTE
Basically, it will not be accessed before initialization the
UIViewController
nib so after loaded the nib the references and the memory will be allocated to the IBOutlet so you have only two way to implement that:1:- By default you have to make it hidden and when you need unhide you can control in the
dataviewcontroller
viewDidLoad
method.2 And the second one write code in
viewDidAppear
orviewDidLoad
in dataviewcontrolleris like luckyShubhra tells:create object of dataviewcontroller in scopeviewcontroller. eg. var dataVCObj = DataViewController(); than using object dataVCObj you can access the iboutlet of button. eg. dataVCObj.AddData
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 ofCAPSPageMenuDelegate
In ScopeViewController, set the delegate of your pager.
And implement the protocol
CAPSPageMenuDelegate