Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder) error in Cocoa and storyboard

后端 未结 4 2088
南方客
南方客 2021-02-07 18:14

I\'ve tried to build a sample Cocoa app on which I want to connect UI components put on storyboard to ViewController.swift as either an IBOutlet or

相关标签:
4条回答
  • 2021-02-07 19:02

    While the answer above correctly states that this isn't the reason for compilation issues, I thought that I would clarify for those who are just looking to eliminate the warning messages altogether. This was what I was looking for when I found this page.

    When you are building your actions and some of the actions change, or get deleted in the storyboard, the outlets remain. Select the controller/window where the older unused actions used to be and you will still see them in the outlets segment of the storyboard within the attributes tab. Remove those old actions/outlets there and then the warning disappear.

    Look for duplicates between the ViewController and the File's Owner. One or both might be holding on to these objects when they shouldn't be. Removing those will remove these soft warnings.

    0 讨论(0)
  • 2021-02-07 19:05
    Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder): missing setter or instance variable
    

    The IBAction methods working like it should, see Apple Dev Forums:

    "This is a known issue ... The messages are harmless and do not indicate a problem with your code."

    Apple Dev Forums: OS X Storyboard failure

    Thats not why your code is not working, you need to fix the following:

    A) Here is my working code to set the title - using self.view.window.title instead self.title:

    @IBAction func btnSetWindowTitle(sender : AnyObject) {
        if self.txtTitle.stringValue != "" {
            println(self.view.window.title)
            println(self.txtTitle.stringValue)
            self.view.window.title = self.txtTitle.stringValue
        }
    }
    

    B) In Interface Builder you need to set NSBox "Box Type" to "Custom": enter image description here

    And that's it: enter image description here

    0 讨论(0)
  • 2021-02-07 19:12

    I've found another easier solution these days while coding.

    Check this out.

    enter image description here

    1) Select File's Owner in Document Outline in the .xib file.

    enter image description here

    2) Specify the class you want the .xib file to connect with.

    enter image description here

    3) Now when you connect outlet to the source file, just use default File's Owner. Much easier.

    enter image description here enter image description here

    4) I guess it's not enough so far. I've met an exception when running called 'loaded the 'xxx' nib but the view outlet was not set'. We should do something more.

    Select the view in Document Outline. Drag from the circle of New Referencing Outlet to the File's Owner in Document Outline.

    Alright, that's the new easier solution. No additional objects should add into the xib. If it doesn't work, leave comments below.

    0 讨论(0)
  • 2021-02-07 19:15

    I think I figured out the right solution.

    enter image description here

    1) Drag an Object into you xib interface.

    enter image description here

    2) Click the Object in the left list you just dragged in.

    enter image description here

    3) Bind the Object to your custom class.(Here my class is a login window controller as example)

    enter image description here

    4) Ctrl drag button to the source code. In the popup window, choose your class name(here in example is Login Window Controller) rather than File's Owner.

    Hope this could help you.

    0 讨论(0)
提交回复
热议问题