ios - Subclassing UITableViewController in Swift -


i subclassed uitableviewcontroller in swift , added custom initializer:

init(schedulecontroller: schedulecontroller) {     self.schedulecontroller = schedulecontroller     super.init(style: uitableviewstyle.plain)     self.title = "routes" } 

now when start app crashes with:

fatal error: use of unimplemented initializer 'init(nibname:bundle:)' class 'shuttle_plan.routesviewcontroller' 

how can solve without adding initializer?

maddening, isn't it? error message tells do: if going call super.init(style:), then must implement init(nibname:bundle:), if there call super:

override init(nibname nibnameornil: string?, bundle nibbundleornil: nsbundle?) {     super.init(nibname:nibnameornil, bundle:nibbundleornil) }  

this, however, raises question of properties. swift won't let implement init(nibname:bundle:) unless initializes uninitialized properties.

  • one obvious solution make properties optionals; implementation shown above legal. in init(schedulecontroller:), have initialize properties after calling super.init.

  • less dramatically, make property var not optional. initialize multiple times: before super.init in initializers, , after super.init in init(schedulecontroller:).

none of those, however, solution use in own code. in code, not call super.init(style:), doing — call super.init(nibname:bundle:) instead. works because:

  • the default style .plain, want

  • even if want .grouped, can specify in associated nib file

the big advantage of approach permits properties non-optional let, do.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -