ViewController.swift
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var nowOnline: UILabel!
override func viewDidLoad() {
setText("NEW");
}
func setText(newText: String){
nowOnline.text = "(newText)"
}
}
这段代码工作正常,但如果我想从另一个类更改它不起作用
class SelectBox {
func select(){
let x = ViewController()
x.setText("From Class") // this line i get error
}
}
线程 1:致命错误:解开包装时意外发现 nil 可选值
编辑:
设置文本函数:
internal func setText(){
var priceLast = Int(self.selectPackPrice - AppDelegate.userCharge - self.selectExPrice)
if(priceLast <= 0){
priceLast = 0;
txtGoPayment.text = "Call"
} else {
txtGoPayment.text = "Payment"
}
txtPackPrice.text = "Price : (self.selectPackPrice) $"
yourCharge.text = "Charge : (AppDelegate.userCharge) $"
priceFinish.text = "Finish Price : (priceLast) $"
}
view.layoutSubviews(( 添加到 setText 为我做到了