func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let newuser = users[indexPath.row]
let usernname = newuser.name! as String
print(usernname)
print(keys[indexPath.row])
let destinationViewController = ChatViewController()
destinationViewController.toUid = keys[indexPath.row]
destinationViewController.topBar.title = usernname
performSegue(withIdentifier: "toChatView", sender: self)
}
鍵[indexPath.row]工作正常,但用戶名有錯誤。它說Segue可選值無
fatal error: unexpectedly found nil while unwrapping an Optional value
但是,當我打印我username
變量,它打印OK
哪裏就是你的執行SEGUE方法? –
嘗試使用if let usernname = newuser.name!作爲字符串{做代碼如果條件} –
@ Mr.UB那麼,它在我的代碼 –