![](/img/trans.png)
[英]Swift - insert item in TableView from another ViewController
[英]SWIFT: cannon insert value to NSTextView From ViewController
我创建了文件ViewController.swift
这是它的内容
import Cocoa
public class ViewController: NSObject {
@IBOutlet var textView: NSTextView!
func InsertText(string:String) {
textView.insertText(string)
}
}
然后我在我的xib中将textView绑定到我的NSTextView
和
现在我想通过控制器从AppDelegate插入文本
我做
let controller = ViewController()
controller.InsertText("Hello")
它抛出一个错误
fatal error: unexpectedly found nil while unwrapping an Optional value
这意味着textView为nil,但为什么为nil以及如何使用另一个类插入文本。 如果我只是在AppDelegate中做同样的事情,它将起作用。
与其let controller = ViewController()
ctrl拖动视图到AppDelegate中,不如将其命名为合理并使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.