我正在尝试从自定义单元格中的按钮到另一个VC执行搜索。单元格内的按钮正在从查询中获取结果,并使用它们对Firebase进行另一个查询并在另一个VC中显示数据。单元格中的每个标签都有一个值,我不明白为什么SEGUE不能按预期工作。任何帮助是极大的赞赏。谢谢!
带有UIButton的单元格
class ptlistCell: UITableViewCell {
@IBOutlet private weak var ptnameLbl: UILabel!
@IBOutlet private weak var assignedmdLbl: UILabel!
@IBOutlet private weak var officemdLbl: UILabel!
@IBOutlet private weak var roomnumberLbl: UILabel!
@IBOutlet private weak var seenoseeLbl: UILabel!
@IBOutlet private weak var assigneddateLbl: UILabel!
var ptdatainfoRef: CollectionReference!
var query: Query?
var patdata = [PTData]()
var delegate: CellDelegate?
@IBOutlet weak var ptDataBtn: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
ptdatainfoRef = Firestore.firestore().collection(PTLIST_REF)
}
func configureCell(ptlist: PTList) {
ptnameLbl.text = ptlist.ptname
assignedmdLbl.text = ptlist.assignedmd
officemdLbl.text = ptlist.officemd
roomnumberLbl.text = ptlist.room
seenoseeLbl.text = ptlist.seenosee
assigneddateLbl.text = ptlist.assigneddate
}
@IBAction func ptdataTapped(_ sender: AnyObject) {
let query = ptdatainfoRef.whereField("ptname", isEqualTo:
(ptnameLbl.text!))
.whereField("assignedmd", isEqualTo:
(assignedmdLbl.text!))
.whereField("officemd", isEqualTo:
(officemdLbl.text!))
.whereField("room", isEqualTo:
(roomnumberLbl.text!))
.whereField("seenosee", isEqualTo:
(seenoseeLbl.text!))
.whereField("assigneddate", isEqualTo:
(assigneddateLbl.text!))
query.getDocuments { (snapshot, error) in
if let err = error {
debugPrint("error getting data: \(err)")
} else {
guard let snap = snapshot else { return }
for document in snap.documents {
let data = document.data()
let ptname = data[PTNAME] as? String ?? ""
let dob = data[DOB] as? String ?? ""
let fin = data[FIN] as? String ?? ""
let officemd = data[OFFICEMD] as? String ?? ""
let assignedmd = data[ASSIGNEDMD] as? String ?? ""
let assigneddate = data[ASSIGNEDDATE] as? String ??
""
let room = data[ROOM] as? String ?? ""
let diagnoses = data[DIAGNOSES] as? String ?? ""
let reasonforadmitorconsult =
data[REASONFORADMITORCONSULT] as? String ?? ""
let goalofhospitalization =
data[GOALOFHOSPITALIZATION] as? String ?? ""
let seenosee = data[SEENOSEE] as? String ?? ""
let notestocbo = data[NOTESTOCBO] as? String ?? ""
let comments = data[COMMENTS] as? String ?? ""
let hosp = data[HOSP] as? String ?? ""
let team = data[TEAM] as? String ?? ""
let newPtdata = PTData (ptname: ptname, dob: dob,
fin: fin, officemd: officemd, assignedmd: assignedmd, assigneddate:
assigneddate, room: room, diagnoses: diagnoses,
reasonforadmitorconsult: reasonforadmitorconsult,
goalofhospitalization: goalofhospitalization, seenosee: seenosee,
notestocbo: notestocbo, comments: comments, hosp: hosp, team: team)
self.patdata.append(newPtdata)
print(document.data()) //data shows in the console
}
}
self.delegate?.callSegueFromCell(cellData: AnyObject.self
as AnyObject)
}
}
}
**单元格**
class ptdataCell2: UITableViewCell {
@IBOutlet weak var ptnameLbl3: UILabel!
@IBOutlet weak var dobLbl3: UILabel!
@IBOutlet weak var finLbl3: UILabel!
@IBOutlet weak var officemdLbl3: UILabel!
@IBOutlet weak var assignedmdLbl3: UILabel!
@IBOutlet weak var assigneddateLbl3: UILabel!
@IBOutlet weak var roomLbl3: UILabel!
@IBOutlet weak var diagnosesLbl3: UILabel!
@IBOutlet weak var reasonforadmitorconsultLbl3: UILabel!
@IBOutlet weak var goalofhospitalizationLbl3: UILabel!
@IBOutlet weak var seenoseeLbl3: UILabel!
@IBOutlet weak var notestocboLbl3: UILabel!
@IBOutlet weak var commentsLbl3: UILabel!
var ptdata: PTData!
override func awakeFromNib() {
super.awakeFromNib()
}
func configureCell(ptdata: PTData) {
ptnameLbl3.text = ptdata.ptname
dobLbl3.text = ptdata.dob
finLbl3.text = ptdata.fin
officemdLbl3.text = ptdata.officemd
assignedmdLbl3.text = ptdata.assignedmd
assigneddateLbl3.text = ptdata.assigneddate
roomLbl3.text = ptdata.room
diagnosesLbl3.text = ptdata.diagnoses
reasonforadmitorconsultLbl3.text =
ptdata.reasonforadmitorconsult
goalofhospitalizationLbl3.text = ptdata.goalofhospitalization
seenoseeLbl3.text = ptdata.seenosee
notestocboLbl3.text = ptdata.notestocbo
commentsLbl3.text = ptdata.comments
}
}
** TableViewController **
protocol CellDelegate {
func callSegueFromCell(cellData dataobject: AnyObject)
}
class patdataTVC: UITableViewController, CellDelegate {
var patdata = [PTData]()
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return patdata.count
}
override func tableView(_ tableView: UITableView, cellForRowAt
indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier:
"ptdataCell2", for: indexPath) as! ptlistCell
cell.delegate = self
return cell
}
func callSegueFromCell(cellData dataobject: AnyObject) {
self.performSegue(withIdentifier: "gotoptdataTVC", sender:
dataobject)
}
}