简体   繁体   中英

viewDidLoad function is not called in Xcode 6.2 swift app but called in Xcode 6.4 swift app on OS X

I'm creating new swift app for OS X:

1) File->New Project -> Cocoa Application -> Select Swift language, Use Storyboards shouldn't be checked.

So I see MainMenu.xib and AppDelegate.swift files in the project.

2) New File -> Cocoa Class -> Class Name: ViewController, Subclass of: NSViewController, language swift, also create Xib file unchecked.

So I see ViewController.swift file in the project.

3) Go to MainMenu.xib Interface Builder, it shows NSWindow object that has NSView. Add ViewController object, connect its Outlet "view" to my NSView object. Then go to Identity Inspector of ViewController and set class to "ViewController".

4) Launch application

So in XCode 6.4 (Yosemite) ViewDidLoad() function in ViewController.swift is called sucessfully, but in XCode 6.2 (Mavericks) it isn't called.

How to fix it? I'm interested in handling ViewController functions viewDidLoad, viewDidAppear, viewDidDisapper. If it is not possible, I want to use some other functions that calls when my window appears, disappears...

I've tried to change File's Owner Class to "ViewController" and connect its Outlet "view" to my NSView object, but it also didn't help.

I did it like this. I am not sure if this is the right way though. It worked anyway.

  1. Open MainMenu.xib
  2. Add a ViewController objects if there was not one.
  3. Link the view to the ViewController object.

In that way viewDidload will be worked.

Xcode Version: 7.3.1, OS X Version: 10.11.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM