swift - Load UIView from xib without storyboard -


i'm trying load nib programmatically without using iboutlets in storyboard.

i've set file owner's custom class , created outlets images , labels. i've created instance of uinib , called instantiatewithowner in custom class manually load nib. i'm trying load nib on uitableviewcontroller.

my question how load xib on view controller without adding uiview view controller using storyboard , without connecting outlets uiview.

there several questions , tutorials how load nib using storyboard , iboutlets, straightforward.

can tell me how go programmatically, in swift?

note: have 2 viewcontrollers in project. vc1 has collectionview image , label. i'm using xib , custom class display selected collectionview in vc2.

you don't have have owner setup. can instantiate nib , reference top level objects created it. having said that, if pass self owner , have outlets connected, works well. it's worth noting if instantiate nib multiple times, value of outlets set new instances each time. if want reference prior ones you'll have capture them in other property.

    // create uinib object nib named mynib in main bundle     let nib = uinib(nibname: "mynib", bundle: nil)      // instante objects in uinib     let toplevelobjects = nib.instantiatewithowner(self /*or nil*/, options: nil)      // use top level objects directly...     let firsttoplevelobject = toplevelobjects[0]      // or use iboutlets     dosomestuff(self.someoutletproperty) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -