gpt4 book ai didi

ios - 通过 segue 传递 User 类型的值

转载 作者:行者123 更新时间:2023-11-28 08:41:19 24 4
gpt4 key购买 nike

我有一个 User 类,里面有很多用户数据。就像联系人应用程序一样,我希望当有人点击联系人时它会加载联系人卡片。通常我使用 prepareForSegue 和 Storyboard segue 来传递 String、Int、Array 等的值,但我似乎无法弄清楚如何发送 User 类型的值。在发送方,我已经正确设置了它,但我不知道如何设置接收 View 。我想发送整个内容而不是使用点语法并单独获取每个元素的原因是因为(就像联系人应用程序一样)我希望用户能够将字段添加到名片中,而我不想除非必须,否则输入我需要传递的所有数据。

用户类:

class User {
var firstName = ""
var lastName = ""
var email = ""
var birthday = ""
var team = ""
var schedule = ""
var service = ""
var position = ""
var phoneNumber = ""
var dateStarted = ""
var profileImgURL = ""
var notes = ""

init (firstName:String, lastName:String, email:String, birthday:String, team:String, schedule:String, service:String, position:String, phoneNumber:String, dateStarted:String, profileImgURL:String, notes:String) {
self.firstName = firstName
self.lastName = lastName
self.email = email
self.birthday = birthday
self.team = team
self.schedule = schedule
self.service = service
self.position = position
self.phoneNumber = phoneNumber
self.dateStarted = dateStarted
self.profileImgURL = profileImgURL
self.notes = notes
}

发件人:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "SeeContactCardSegue" {
if let destVC = segue.destinationViewController as? ContactCardTVC {
if let indexPath = tableView.indexPathForSelectedRow {
let user = users[indexPath.row]
destVC.user = user
}
}
}
}

接收者:

var user:User = ???

我收到一条错误消息,提示用户需要初始化,这在大多数情况下都是我遇到的,但我不确定如何初始化它。我错过了什么吗?

最佳答案

强制解包。它应该可以正常工作。

var user: 用户!

关于ios - 通过 segue 传递 User 类型的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36434877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com