ios - Handling of awakeFromNib for the object that is File's Owner -


i know there many related questions why awakefromnib not called when instantiating view. message view awaken nib sent view , message not delivered file's owner. saw why won't awakefromnib fire?.

so, happen if create view's instance file's owner in xib file?

in other word, have own custom view named mycustomview.swift , mycustomview.xib. , in xib file, set file's owner mycustomview. so, when create instance of mycustomview, awakefromnib called? in case, awakefromnib doesn't seem called. however, view instantiated. so, me strange awakefromnib not called.

could explain thing?

fyi: prepared basecustomview.swift. basecustomview has 2 init.

override init(frame: cgrect) {         super.init(frame: frame)         commoninit()     } 

and

required init?(coder adecoder: nscoder) {         super.init(coder: adecoder)         commoninit()     } 

and commoninit() this.

private func commoninit() {         // load custom view's xib         let bundle = bundle(for: type(of: self))         let nib = uinib(nibname: self.classname(), bundle: bundle)         let view = nib.instantiate(withowner: self, options: nil).first as! uiview         addsubview(view)          // make custom view's size same size         view.translatesautoresizingmaskintoconstraints = false         let bindings = ["view": view]         addconstraints(nslayoutconstraint.constraints(withvisualformat: "h:|[view]|",             options:nslayoutformatoptions(rawvalue: 0),             metrics:nil,             views: bindings))         addconstraints(nslayoutconstraint.constraints(withvisualformat: "v:|[view]|",             options:nslayoutformatoptions(rawvalue: 0),             metrics:nil,             views: bindings))     } 

and customview class overrides basecustomview. in addition, customview's file's owner customview itself.

more edit: custom view class this. , awakefromnib() not called.

final class mycustomview: basecustomview {      override func awakefromnib() {     //     }  } 

the "file's owner" item in nib bit special: isn't real object in archive, other items are. it's placeholder, that's filled in preexisting object when nib instantiated.

so, file's owner not being "awoken" nib other objects are. it's created before nib unarchived. therefore, doesn't make sense receive awakefromnib.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -