uiviewcontroller - Property not initialized at super.init call -
uiviewcontroller - Property not initialized at super.init call -
i have next init
method in view controller:
init(mainviewcontroller: uiviewcontroller, settingsviewcontroller: uiviewcontroller, gap: int) { self.mainviewcontroller = mainviewcontroller self.settingsviewcontroller = settingsviewcontroller self.gap = gap self.setupscrollview() // error here super.init(nibname: nil, bundle: nil) //and here. }
the self.setupscrollview
method looks this:
func setupscrollview() { self.scrollview = uiscrollview(frame: cgrectzero) self.scrollview.settranslatesautoresizingmaskintoconstraints(false) self.view.addsubview(self.scrollview) }
the errors are:
self used before super.init call
, property 'self.scrollview' not initialized @ super.init call
i've looked @ similar post without luck. help appreciated!
you can declaring scrollview
optional , moving setup method phone call below super.init
call. declaration this:
var scrollview : uiscrollview?
and initialisation:
init(mainviewcontroller: uiviewcontroller, settingsviewcontroller: uiviewcontroller, gap: int) { //other stuff super.init(nibname: nil, bundle: nil) self.setupscrollview() } func setupscrollview() { scrollview = uiscrollview(frame: cgrectzero) scrollview!.settranslatesautoresizingmaskintoconstraints(false) view.addsubview(scrollview!) }
uiviewcontroller uiscrollview initialization swift ios8
Comments
Post a Comment