d0ye
d0ye

Reputation: 1610

iOS @IBOutlet views all be nil only in iOS 8

I'm using Xcode8 and worked on a OC mix swift project

With my new viewController in my project I'm using swift 2.3 I create the ViewController simply by creating new file and with (Also crate XIB file) checked (so it could auto binding the VC Since My past codes is OC so I init my VC with

_theViewController = [[TheViewController alloc] init];

and want to set frame or other init thing with the @IBOutlet views

It worked all well (the xib loaded as expect and after break in viewDidLoad I could see those Outlet instance(not nil)in iOS 9 and +

but under iOS 8 whenever in viewDidLoad viewWillAppear viewDidAppear those IBOutlet views always be nil, And after I comment all init thing,It seems it just not load my xib view as I want

I've tried some solutions I could find but seems not worked(I'm sure xib is linked with VC.(it created and linked by xcode after all) overriding some function or some other ways hope for force loading it )

any suggestion will be appreciated T_T

PS: I'm not using storyboard ,just using this xib tech 4 quick and viewable development

Upvotes: 3

Views: 485

Answers (1)

GoodSp33d
GoodSp33d

Reputation: 6282

To initialize a view controller object using a nib file, create your view controller class programmatically and initialize it using the init(nibName:bundle:) method.

When its views are requested, the view controller loads them from the nib file.

API reference: https://developer.apple.com/reference/uikit/uiviewcontroller

Upvotes: 5

Related Questions