在Cocoa和storyboard中无法连接(storyboard)插件(NSApplication)到(NSNibExternalObjectPlaceholder)错误 [英] Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder) error in Cocoa and storyboard

查看:1932
本文介绍了在Cocoa和storyboard中无法连接(storyboard)插件(NSApplication)到(NSNibExternalObjectPlaceholder)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个示例Cocoa应用程序,我想连接UI组件放在故事板上 ViewController.swift 作为 IBOutlet IBAction 。但是,当我试图将storyboard上的UI组件(例如 NSButton )拖动到 ViewController.swift 创建一个 @IBAction 方法,然后运行应用程序,结果应用程序在控制台中记录以下消息,当然应用程序不响应我点击按钮。 / p>

 无法将(故事板)插座从(NSApplication)连接到(NSNibExternalObjectPlaceholder):缺少setter或实例变量

如何正确使用 IBAction 方法?



您的信息在这里是我的 ViewController.swift

  import Cocoa 

class ViewController:NSViewController {
@IBOutlet var txtTitle:NSTextField
@IBOutlet var boxColor:NSBox

override func viewDidLoad(){
super.viewDidLoad()
}

func colorChanged(cp:NSColorPanel){
let c:NSColor = cp.color;
self.boxColor.fillColor = c
}

@IBAction func btnSetColor(sender:AnyObject){
let cp:NSColorPanel = NSColorPanel.sharedColorPanel $ b cp.setTarget(self)
cp.setAction(colorChanged:)
cp.orderFront(nil)

}

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

我在OS X 10.10 Yosemite上使用Xcode 6 beta。

解决方案

 无法连接(故事板)插座从(NSApplication)到(NSNibExternalObjectPlaceholder):缺少setter或实例变量

IBAction方法,请参阅Apple开发人员论坛:


这是已知问题...邮件无害, >
表示您的代码有问题。


Apple开发者论坛:OS X故事板失败



为什么你的代码不工作,你需要修复以下:



A)这是我的工作代码设置标题 - 使用 self.view.window .title 改为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。 B)在Interface Builder中,您需要使用以下方法:a。在界面生成器中创建一个名为将NSBox框类型设置为自定义:
>



这就是:


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 IBAction. However, when I tried to control-drag the UI components on storyboard (such as NSButton) to ViewController.swift and create a @IBAction method, and then run the app, the resultant app logs the following message in console and of course the app doesn't respond to me tapping the button.

Failed to connect (storyboard) outlet from (NSApplication) to (NSNibExternalObjectPlaceholder): missing setter or instance variable

How can I use the IBAction method properly?

For your information here's my ViewController.swift:

import Cocoa

class ViewController: NSViewController {
    @IBOutlet var txtTitle : NSTextField
    @IBOutlet var boxColor : NSBox

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func colorChanged(cp: NSColorPanel) {
        let c:NSColor = cp.color;
        self.boxColor.fillColor = c
    }

    @IBAction func btnSetColor(sender : AnyObject) {
        let cp:NSColorPanel = NSColorPanel.sharedColorPanel()
        cp.setTarget(self)
        cp.setAction("colorChanged:")
        cp.orderFront(nil)

    }

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

I use Xcode 6 beta on OS X 10.10 Yosemite. And started the template with storyboard being on.

解决方案

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":

And that's it:

这篇关于在Cocoa和storyboard中无法连接(storyboard)插件(NSApplication)到(NSNibExternalObjectPlaceholder)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆