【发布时间】:2014-12-07 15:39:59
【问题描述】:
我创建了文件 ViewController.swift
这是它的内容
import Cocoa
public class ViewController: NSObject {
@IBOutlet var textView: NSTextView!
func InsertText(string:String) {
textView.insertText(string)
}
}
然后我将 textView 绑定到我的 xib 中的 NSTextView
和
现在我想通过控制器从 AppDelegate 插入文本
我愿意
let controller = ViewController()
controller.InsertText("Hello")
会报错
fatal error: unexpectedly found nil while unwrapping an Optional value
这意味着 textView 在 nil,但为什么它是 nil 以及如何使用另一个类插入文本。如果我只是在 AppDelegate 中做同样的事情。
【问题讨论】:
标签: swift