我有一个问题,我单击 tableviewcell 并且它应该填充详细视图控制器,但是当我单击单元格时会弹出此错误。
import UIKit
import Former
import Parse
import MapKit
import Material
import CoreLocation
class EventDetailViewController: FormViewController, MKMapViewDelegate, CLLocationManagerDelegate {
// MARK: Public
var event: PFObject?
var organizer: PFUser?
var currentUserStatus = 2
var confirmedUsers = [PFObject]()
var maybeUsers = [PFObject]()
var invitedUsers = [PFObject]()
var confirmedUserIDs = [String]()
var maybeUserIDs = [String]()
var invitedUserIDSs = [String]()
// MARK: Public
override func viewDidLoad() {
super.viewDidLoad()
// Configure UI
title = "Event Details"
tableView.contentInset.top = 0
tableView.contentInset.bottom = 30
navigationItem.leftBarButtonItem = UIBarButtonItem(image: Icon.cm.close, style: .plain, target: self, action: #selector(cancelButtonPressed))
organizer = event?.object(forKey: PF_EVENTS_ORGANIZER) as? PFUser
organizer!.fetchInBackground { (user: PFObject?, error: Error?) in
if error == nil {
self.insertEventDetail()
for pointer in (self.event?.object(forKey: PF_EVENTS_CONFIRMED) as! [PFUser]) {
pointer.fetchInBackground(block: { (user: PFObject?, error: Error?) in
if error == nil {
if user?.objectId == PFUser.current()?.objectId {
self.currentUserStatus = 0
self.choiceRow.configure(handler: {
$0.selectedIndex = self.currentUserStatus
})
}
self.confirmedUsers.append(user!)
self.confirmedUserIDs.append(user!.objectId!)
if pointer == (self.event?.object(forKey: PF_EVENTS_CONFIRMED) as! [PFUser]).last {
// All users have been downloaded
self.insertUsers(users: self.confirmedUsers, header: "Going", section: 2)
if self.currentUserStatus == 0 {
self.former.insertUpdate(rowFormer: self.newRow, toIndexPath: IndexPath(row: 0, section: 2), rowAnimation: .fade)
}
}
}
})
}
for pointer in (self.event?.object(forKey: PF_EVENTS_MAYBE) as! [PFUser]) {
pointer.fetchInBackground(block: { (user: PFObject?, error: Error?) in
if error == nil {
if user?.objectId == PFUser.current()?.objectId {
self.currentUserStatus = 1
self.choiceRow.configure(handler: {
$0.selectedIndex = self.currentUserStatus
})
}
self.maybeUsers.append(user!)
self.maybeUserIDs.append(user!.objectId!)
if pointer == (self.event?.object(forKey: PF_EVENTS_MAYBE) as! [PFUser]).last {
// All users have been downloaded
var section = 3
if self.former.sectionFormers.count < 2 {
section = 2
}
self.insertUsers(users: self.maybeUsers, header: "Maybe", section: section)
if self.currentUserStatus == 1 {
self.former.insertUpdate(rowFormer: self.newRow, toIndexPath: IndexPath(row: 0, section: section), rowAnimation: .fade)
}
}
}
})
}
for pointer in (self.event?.object(forKey: PF_EVENTS_INVITE_TO) as! [PFUser]) {
pointer.fetchInBackground(block: { (user: PFObject?, error: Error?) in
if error == nil {
self.invitedUsers.append(user!)
if pointer == (self.event?.object(forKey: PF_EVENTS_INVITE_TO) as! [PFUser]).last {
// All users have been downloaded
var section = 4
if self.former.sectionFormers.count == 2 {
section = 3
} else if self.former.sectionFormers.count < 2 {
section = 2
}
self.insertUsers(users: self.invitedUsers, header: "Invited", section: section)
}
}
})
}
if (self.event?.object(forKey: PF_EVENTS_CONFIRMED) as! [PFUser]).count == 0 {
self.insertEmpty(header: "Confirmed")
}
if (self.event?.object(forKey: PF_EVENTS_MAYBE) as! [PFUser]).count == 0 {
self.insertEmpty(header: "Maybe")
}
if (self.event?.object(forKey: PF_EVENTS_INVITE_TO) as! [PFUser]).count == 0 {
self.insertEmpty(header: "Invited")
}
}
}
if organizer?.objectId == PFUser.current()?.objectId {
navigationItem.rightBarButtonItem = UIBarButtonItem(image: Icon.cm.edit, style: .plain, target: self, action: #selector(editButtonPressed))
}
}
// MARK: Private
private func insertUsers(users: [PFObject], header: String, section: Int) {
var userRows = [LabelRowFormer<ProfileImageCell>]()
for user in users {
if user.objectId != PFUser.current()?.objectId {
userRows.append(LabelRowFormer<ProfileImageCell>(instantiateType: .Nib(nibName: "ProfileImageCell")) {
$0.iconView.backgroundColor = MAIN_COLOR
$0.iconView.layer.borderWidth = 1
$0.iconView.layer.borderColor = MAIN_COLOR?.cgColor
$0.iconView.image = UIImage(named: "profile_blank")
$0.iconView.file = user[PF_USER_PICTURE] as? PFFile
$0.iconView.loadInBackground()
$0.titleLabel.textColor = UIColor.black
}.configure {
$0.text = user[PF_USER_FULLNAME] as? String
$0.rowHeight = 60
}.onSelected { [weak self] _ in
self?.former.deselect(animated: true)
let profileVC = PublicProfileViewController()
profileVC.user = user
self?.navigationController?.pushViewController(profileVC, animated: true)
})
}
}
self.former.insert(sectionFormer: (sectionFormer: SectionFormer(rowFormers: userRows).set(headerViewFormer: TableFunctions.createHeader(text: header))) as! SectionFormer, toSection: section)
self.former.reload()
}
private func insertEmpty(header: String) {
let zeroRow = LabelRowFormer<ImageCell>(instantiateType: .Nib(nibName: "ImageCell")) { _ in
}.configure {
$0.rowHeight = 0
}
下面是该代码给我一个 EXC 错误指令的地方
self.former.append(sectionFormer: (sectionFormer: SectionFormer(rowFormer: zeroRow).set(headerViewFormer: TableFunctions.createHeader(text: header))) as! SectionFormer)
self.former.reload()
}