在 segue 中使用 class 时遇到问题

Having issues using a class within a segue

试图让 'edit' VC 传回 'display' VC 用户通过 Storyboard segue 更新但难以存储的新信息用户输入我初始化的 class 'Event'

我一直收到这个错误

Cannot invoke initializer for type 'Event' with an argument list of type '(eventName: String, eventLocation: String, eventStart: String, eventDescription: String, eventHost: String)'

我的编辑(来源)VC(准备...时出错)

class EditEventDetailTableViewController: UITableViewController {

@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var eventName: UITextField!
@IBOutlet weak var eventStartDate: UITextField!
@IBOutlet weak var eventLocation: UITextField!
@IBOutlet weak var eventDescription: UITextView!
@IBOutlet weak var eventHost: UITextField!

var event:Event?
var eventUpdate:Event?

override func viewDidLoad() {
    super.viewDidLoad()

    //imageView.image = detail?.photo
    eventName.text = event?.eventName
    eventStartDate.text = event?.eventStart
    eventLocation.text = event?.eventLocation
    eventDescription.text = event?.eventDescription
    eventHost.text = event?.eventHost

    guard let urlString = (event?.eventCoverUrl) else { return  }
    let url = URL(string: urlString)
         guard url != nil else {
             //Couldn't create url object
             return
         }
    self.imageView.sd_setImage(with: url) { (image, error, cacheType, url) in
        self.imageView.image = image
    }
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {


   if let eventName = eventName.text?.trimmingCharacters(in: .whitespacesAndNewlines),
       let eventStart = eventStartDate.text?.trimmingCharacters(in: .whitespacesAndNewlines),
       let eventLocation = eventLocation.text?.trimmingCharacters(in: .whitespacesAndNewlines),
       let eventDescription = eventDescription.text?.trimmingCharacters(in: .whitespacesAndNewlines),
       let eventHost = eventHost.text?.trimmingCharacters(in: .whitespacesAndNewlines) {
    self.event = Event(eventName: eventName, eventLocation: eventLocation, eventStart: eventStart, eventDescription: eventDescription, eventHost: eventHost)
   }}}

这是我的 class

class Event {

var adminUser:String?
var eventCreated:Date?
var eventId:String?
var eventName:String?
var eventCoverUrl:String?
var eventLocation:String?
var eventStart:String?
var eventEnd:Date?
var eventStatus:String?
//var eventParticipants: [String?]
var eventDescription:String?
var eventDeleteDate:Date?
var eventHost:String?


init?(snapshot:DocumentSnapshot){

    self.eventId = snapshot.get("eventId") as? String ?? "No event Id"
    self.adminUser = snapshot.get("adminUser") as? String ?? "No admin user"
    //self.eventCreated = snapshot.get("eventCreated") as? Date ?? "No Event Created Date"
    self.eventName = snapshot.get("eventName") as? String ?? "No Event Name"
    self.eventCoverUrl = snapshot.get("eventCoverUrl") as? String ?? "No Cover URL"
    self.eventLocation = snapshot.get("eventLocation") as? String ?? "No Location"
    self.eventStart = snapshot.get("eventStart") as? String ?? "No Start Date"
    self.eventDescription = snapshot.get("eventDescription") as? String ?? "No Event Description"
    self.eventHost = snapshot.get("eventHost") as? String ?? "No Event Host"
    self.eventStatus = snapshot.get("eventStatus") as? String ?? "No Event Status"

}

init(adminUser:String?, eventId:String?, eventName:String?, eventCoverUrl:String?, eventLocation:String?, eventStart:String?, eventStatus:String?, eventDescription:String?, eventHost:String?) {

    self.adminUser = adminUser ?? "No \(LocalizedError.self)"
    self.eventId = eventId ?? "No \(LocalizedError.self)"
    self.eventName = eventName ?? "No \(LocalizedError.self)"
    self.eventCoverUrl = eventCoverUrl ?? "No \(LocalizedError.self)"
    self.eventLocation = eventLocation ?? "No \(LocalizedError.self)"
    self.eventStart = eventStart ?? "No \(LocalizedError.self)"
    self.eventStatus = eventStatus ?? "No \(LocalizedError.self)"
    self.eventDescription = eventDescription ?? "No \(LocalizedError.self)"
    self.eventHost = eventHost ?? "No \(LocalizedError.self)"
}
}

我已经尝试了很多方法,但没有任何方法可以让我接受编辑字段的用户输入来创建一个 'event',然后通过已经存在的 unwind segue 将其传递到我的显示(目标)VC正在工作。

这是事件 class 的更新代码,更新后的参数初始化为空字符串。其他的都和上面一样。

var adminUser = ""
var eventCreated = ""
var eventId = ""
var eventName = ""
var eventCoverUrl = ""
var eventLocation = ""
var eventStart = ""
var eventEnd:Date?
var eventStatus:String?
//var eventParticipants: [String?]
var eventDescription = ""
var eventDeleteDate = ""
var eventHost = ""

您不能在函数调用中遗漏参数。 Event(eventName, eventLocation, eventStart, eventDescription, eventHost) 未定义,因为实际方法是 Event(adminUser, eventId, eventName, eventCoverUrl, eventLocation, eventStart, eventStatus, eventDescription, eventHost) 您需要将 prepareForSegue 中的最后一行更改为:

self.event = Event(adminUser: adminUser, eventId: eventId, eventName: eventName, eventCoverUrl: eventCoverUrl, eventLocation: eventLocation, eventStart: eventStart, eventStatus:eventStatus, eventDescription: eventDescription, eventHost: eventHost)