ios - Connecting Objects with two View controllers in Swift -
in project have 2 view controllers, , having trouble connecting objects such uiimageview view controller. when try create iboutlet, tells me "could not insert new outlet collection: not find information class named uiviewcontroller". believe problem stems fact original declaration of class follows:
class uiviewcontroller: uiviewcontroller {
when in fact view controller named mainscene instead. however, when change first uiviewcontroller think should (mainscene), doesn't show me option of connecting iboutlet...
class mainscene: uiviewcontroller {
so, have 2 questions.
do need have whole separate class second uiviewcontroller , solve issues?
is there better way link objects uiviewcontroller or doing horribly wrong (the scenario)?
thanks much
short answer: 1. yes, , yes. 2. there's no better way, , you're not doing horribly wrong. (you missed step.)
you have 2 view controllers. assuming different, subclass each 1 uiviewcontroller
different name. e.g., mainsceneviewcontroller , othersceneviewcontroller.
your mainsceneviewcontroller , othersceneviewcontroller each have own properties , iboutlets.
where you're stuck, needing change class of viewcontroller within interface builder match class name in .swift file, ib knows outlets can connect view controller.
each scene in storyboard corresponds view controller. when segue performed, ios instantiates view controller storyboard.
while possible have 1 view controller subclass, , use same subclass different views, doesn't happen often.
update:
subclassing lets add properties , methods class, , override superclass.
in comment, uiviewcontroller
class, , mainsceneviewcontroller
subclassed uiviewcontroller
. second view controller, class othersceneviewcontroller: uiviewcontroller {
, other scene require different properties , methods main scene view controller.
you can read more inheritance in swift programming language guide.
Comments
Post a Comment