ios - Must call a designated initializer of the superclass 'UIViewController' in Swift 1.2 -


i have following init method worked perfect before swift 1.2.

init(items: nsarray, views: nsarray, showpagecontrol: bool, navbarbackground: uicolor){   super.init() 

in swift 1.2 line super.init() raises error:

must call designated initializer of superclass 'uiviewcontroller' 

the problem have 2 possible super init methods call 1 codec , other nib. both of not have access in init method.

see full class here line of error this.

how can correct init method make work swift 1.2?

class slpagingviewswift: uiviewcontroller, uiscrollviewdelegate {    init(items: nsarray, views: nsarray, showpagecontrol: bool, navbarbackground: uicolor){         super.init()         needtoshowpagecontrol             = showpagecontrol         navigationbarview.backgroundcolor = navbarbackground         isuserinteraction                 = true         var i: int                        = 0         item in items{             if item.iskindofclass(uiview.classforcoder()){                 var v             = item uiview                 var vsize: cgsize = v.iskindofclass(uilabel.classforcoder()) ? self.getlabelsize(v uilabel) : v.frame.size                 var originx       = (self.screensize.width/2.0 - vsize.width/2.0) + cgfloat(i * 100)                 v.frame           = cgrectmake(originx, 8, vsize.width, vsize.height)                 v.tag             =                 var tap           = uitapgesturerecognizer(target: self, action: "taponheader:")                 v.addgesturerecognizer(tap)                 v.userinteractionenabled = true                 self.navigationbarview.addsubview(v)                 self.navitems.addobject(v)                 i++             }         }          if (views.count > 0){             var controllerkeys = nsmutablearray()             = 0             controller in views{                 if controller.iskindofclass(uiview.classforcoder()){                     var ctr = controller uiview                     ctr.tag =                     controllerkeys.addobject(nsnumber(integer: i))                 }                 else if controller.iskindofclass(uiviewcontroller.classforcoder()){                     var ctr      = controller uiviewcontroller                     ctr.view.tag =                     controllerkeys.addobject(nsnumber(integer: i))                 }                 i++             }              if controllerkeys.count == views.count {                self.viewcontrollers = nsdictionary(objects: views, forkeys: controllerkeys)             }             else{                 var exc = nsexception(name: "view controllers error", reason: "some objects in viewcontrollers not kind of uiviewcontroller!", userinfo: nil)                 exc.raise()             }         }     }  } 

full code

you writing view controller class other people use part of own app. if view controller have nib file, doing wrong , have been wrong: allow caller supply nib file name as 1 of parameters of initializer, call init(nibname:bundle:) , pass value along.

but gather view controller uses default empty automatic view, not problem in actual fact.

therefore you'll call init(nibname:bundle:), , since view controller has no nib file, pass nil nib name. in fact super.init() doing in earlier version of swift - calling init(nibname:bundle:) nil values you. nothing lost or changed.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -