我正在尝试从一个视图切换到另一个视图,但我收到此错误,我不知道为什么我会收到错误。
我使用此功能转到下一个控制器:
func showChatControllerForGroup(_ user: [User], groupName: String) {
let vc: GroupChatMessangingViewController = self.storyboard?.instantiateViewController(withIdentifier: "GroupChatMessangingViewController") as! GroupChatMessangingViewController
//it crashed above here
vc.group?.members = user
vc.group?.name = groupName
self.navigationController?.pushViewController(vc, animated: true)
}
打电话给我,我在另一个视图中调用它:
var group: Group? {
didSet {
navigationItem.title = group?.name
}
}
var chosenUser: [User] = []
let user = self.chosenUser
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Create", style: .plain, target: self, action: #selector(createGroup))
// Do any additional setup after loading the view.
}
@objc func createGroup(){
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionReveal
transition.subtype = kCATransitionFromBottom
navigationController?.view.layer.add(transition, forKey: nil)
_ = navigationController?.popViewController(animated: true)
let user = self.chosenUser
self.nextVC.showChatControllerForGroup(user, groupName: groupNameTextField.text!) }
以防万一有人需要查看我的用户类:
class User {
var id: String?
var name: String?
var email: String?
var profileImageUrl: String?
var lastMessage: String?
var timestamp: String? //reason why this exist was because in mainmenu, we appended users, not msssage
init() {
}
init(dictionary: [String: AnyObject]) {
self.id = dictionary["id"] as? String
self.name = dictionary["name"] as? String
self.email = dictionary["email"] as? String
self.profileImageUrl = dictionary["profileImageUrl"] as? String
}
}
我的小组课程:
class Group {
var id: String?
var name: String?
var members: [User]!
var groupImageUrl: String?
var lastMessage: String?
var timestamp: String?
init() {
}
init(dictionary: [String: AnyObject]) {
self.id = dictionary["id"] as? String
self.name = dictionary["name"] as? String
}}
有什么理由导致它崩溃吗?
答案 0 :(得分:0)
我的猜测是你在
let vc: GroupChatMessangingViewController = self.storyboard?.instantiateViewController(withIdentifier: "GroupChatMessangingViewController") as! GroupChatMessangingViewController
你打错了故事板。检查并查看您是否在正确的故事板中。