【发布时间】:2015-04-12 00:46:09
【问题描述】:
我正在尝试编写一个 OSX 应用程序。这个应用程序的一个功能是它显示机器 IP 地址。 程序打开时获取地址(AppDelegate.swift):
@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
var ipadd:String = ""
var path:String = ""
var status:String = ""
func applicationDidFinishLaunching(aNotification: NSNotification) {
ipadd = getIFAddress() //<-- ip stored in here as String
println(ipadd) //successfully prints out the ip
ViewController.setIpDisp(ipadd) //error on this line
}
...
}
在 ViewController.swift 中:
class ViewController: NSViewController {
@IBOutlet weak var ip: NSTextField!
...
func setIpDisp(ipin: String){
ip.stringValue = ipin
}
确切地说,错误是“无法使用类型为'(String)'的参数列表调用'setIpDisp'
谢谢
【问题讨论】:
-
函数不是静态的。您需要一个实例来调用它。我认为正确的想法是发送一条消息并在您的控制器中处理该消息。
标签: xcode swift viewcontroller appdelegate