当我尝试将Event类的详细信息传递给另一个控制器时,我收到一条错误消息“致命错误:在展开Optional值时意外发现nil”。
这是我的视图控制器,它发送信息:
var eventDetailsController: EventDetailsController!
func showDetailView(event: Events){
let mainStoryBoarrd: UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
let detailsViewController: UIViewController = mainStoryBoarrd.instantiateViewControllerWithIdentifier("eventDetailsID")
print(event) // this prints the event fine showing that the event variable is not nil
eventDetailsController?.event = event //this sends all info as nil
self.presentViewController(detailsViewController, animated: true, completion: nil)
}
这是我将数据发送到的类:
var event: Events! {
didSet {
eventPriceLabel.text = event!.date //does nothing cause nil
}
}
override func viewDidLoad() {
super.viewDidLoad()
let string = event?.name
print(string)// prints null
}
我的活动课程:
class Events: NSObject {
var name: String!
var date: String!
var address: String!
var ticketPrice: Int!