ios - All IBOutlets are nil -


hello initializing viewcontroller using code:

 var aboutusviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("aboutusviewcontroller") aboutusviewcontroller 

after move aboutviewcontroller. iboutlets on aboutviewcontroller nil! why so? using mmdrawer library in order have side bar menu.

 var aboutusviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("aboutusviewcontroller") aboutusviewcontroller           var aboutusnavcontroller = uinavigationcontroller(rootviewcontroller: aboutusviewcontroller)          var appdelegate: appdelegate = uiapplication.sharedapplication().delegate appdelegate          appdelegate.centercontainer!.centerviewcontroller = aboutusnavcontroller         appdelegate.centercontainer!.toggledrawerside(mmdrawerside.left, animated: true, completion: nil) 

on side bar choosing menu item , after creating aboutviewcontroller , moving left... problem when initialize controller , outlets nil

i having such kind of problem when using pageviewcontroller:

class viewcontroller: uiviewcontroller, uipageviewcontrollerdatasource, uipageviewcontrollerdelegate {   let pagetitles = ["title 1", "title 2", "title 3", "title 4"] var images = ["long3","long4","long1","long2"] var count = 0   var pageviewcontroller : uipageviewcontroller!  override func viewdidload() {     super.viewdidload()     reset()     // additional setup after loading view, typically nib. }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func reset() {     /* getting page view controller */     pageviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("pageviewcontroller") uipageviewcontroller     self.pageviewcontroller.datasource = self      let pagecontentviewcontroller = self.viewcontrolleratindex(0)     self.pageviewcontroller.setviewcontrollers([pagecontentviewcontroller!], direction: uipageviewcontrollernavigationdirection.forward, animated: true, completion: nil)      /* substracting 30 because have start again button height 30*/     self.pageviewcontroller.view.frame = cgrectmake(0, 0, self.view.frame.width, self.view.frame.height - 30)     self.addchildviewcontroller(pageviewcontroller)     self.view.addsubview(pageviewcontroller.view)     self.pageviewcontroller.didmovetoparentviewcontroller(self) }    func pageviewcontroller(pageviewcontroller: uipageviewcontroller, viewcontrollerafterviewcontroller viewcontroller: uiviewcontroller) -> uiviewcontroller? {      var index = (viewcontroller pagecontentviewcontroller).pageindex!     index++     if (index >= self.images.count){         return nil     }      return self.viewcontrolleratindex(index) }   func pageviewcontroller(pageviewcontroller: uipageviewcontroller, viewcontrollerbeforeviewcontroller viewcontroller: uiviewcontroller) -> uiviewcontroller? {     var index = (viewcontroller pagecontentviewcontroller).pageindex!      if index<=0 {         return nil     }     index--     return self.viewcontrolleratindex(index) }  func viewcontrolleratindex(index : int) -> uiviewcontroller? {     if((self.pagetitles.count == 0) || (index >= self.pagetitles.count)) {         return nil     }     let pagecontentviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("pagecontentviewcontroller") pagecontentviewcontroller      pagecontentviewcontroller.imagename = self.images[index]     pagecontentviewcontroller.titletext = self.pagetitles[index]     pagecontentviewcontroller.pageindex = index     return pagecontentviewcontroller }  func presentationcountforpageviewcontroller(pageviewcontroller: uipageviewcontroller) -> int {     return pagetitles.count }  func presentationindexforpageviewcontroller(pageviewcontroller: uipageviewcontroller) -> int {     return 0     }  }    class pagecontentviewcontroller: uipageviewcontroller {   @iboutlet var imageviewmain: uiimageview!  @iboutlet var labelmain: uilabel!  var pageindex: int! var titletext: string! var imagename: string!   override func viewdidload() {     super.viewdidload()      self.imageviewmain.image = uiimage(named:imagename)     self.labelmain.text = self.titletext     self.labelmain.alpha = 0.1     uiview.animatewithduration(1.0, animations:{ ()-> void in         self.labelmain.alpha = 1.0     })     // additional setup after loading view. }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }   /* // mark: - navigation      // in storyboard-based application, want little preparation before navigation     override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         // new view controller using segue.destinationviewcontroller.         // pass selected object new view controller.     }     */  } 

i having problem label , image outlet nil!!! same problem had using mmdrawer library. same situation. not using segues ! think because of outlets nil

i assume you're looking @ outlets after instantiating scene (you'll see behavior if using segues , trying use outlets in prepareforsegue). outlets not hooked until after present/push scene, view loaded, , viewdidload called.

bottom line, not try use outlets prior viewdidload being called (i.e. not use outlets after instantiating scene). instead, pass needed data destination scene (e.g. string property), , viewdidload of destination should populate outlet.

for example, might have property in aboutusviewcontroller:

var message: string! 

when instantiate aboutusviewcontroller, you'd set property:

let aboutusviewcontroller = self.storyboard?.instantiateviewcontrollerwithidentifier("aboutusviewcontroller") aboutusviewcontroller // use `as!` in swift 1.2  aboutusviewcontroller.message = "some message"  presentviewcontroller(aboutusviewcontroller, animated: true, completion: nil) 

and viewdidload of aboutusviewcontroller use property populate outlet accordingly:

override func viewdidload() {     super.viewdidload()      label1.text = message } 

but never have originating view controller try set/adjust outlets of destination scene. that's responsibility of aboutusviewcontroller.


just confirm, outlets hooked properly? below shows 2 ways confirm hooked properly.

when select view controller in interface builder , in connections inspector, see outlets hooked there? in following snapshot, label1 hooked up, label2 not:

enter image description here

or when @ code, , @ outlets, see solid dots in left margin (meaning outlet hooked up) or empty dots (meaning outlet not hooked up)?

enter image description here


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -