我想不出更好的方法来做到这一点。我将学生对象的所有属性映射到二维数组中。所以我的电视有几个部分。
我也不能使用静态表视图,如果是这样,这个问题就不会存在。
所以我在 TVC 中的代码
let currentUser = PFUser.currentUser()! as! MyUser
var membershipSection:[[String:String]]!
var detailsSection:[[String:String]]!
var emergancySection:[[String:String]]!
var medicalSection:[[String:String]]!
var titlesForSection = ["MEMBERSHIP", "DETAILS", "EMERGANCY CONTACT", "MEDICAL HISTORY"]
var combo = [[[String:String]]]() // Data Source for TableView
// 下面是从ViewDidLoad中调用的
func loadDisplayDataSource() {
combo.removeAll(keepCapacity: true)
var idString = "Awaiting ID Generation"
if student.objectId != nil {
idString = student.objectId!
}
membershipSection = [["Sessions":student.sessionsRemaining], ["Details":""], ["ID":idString]]
detailsSection = [["First Name":student.firstName], ["Last Name":student.lastName], ["DOB":""], ["Address":""], ["Phone":""], ["Email":student.email], ["Occupation":""]]
emergancySection = [["Name":""], ["Phone":""]]
medicalSection = [["Recent Surgery":""], ["Hypertension":""], ["Diabetes":""], ["Caradic":""], ["Epilesy":""], ["Syncope":""], ["Medications":""], ["Medical Details":""], ["Other Injuries":""]]
combo.append(membershipSection)
combo.append(detailsSection)
combo.append(emergancySection)
combo.append(medicalSection)
self.tableView.beginUpdates()
var range = NSMakeRange(0, self.numberOfSectionsInTableView(self.tableView))
var sections = NSIndexSet(indexesInRange: range)
self.tableView.deleteSections(sections, withRowAnimation: UITableViewRowAnimation.None)
self.tableView.insertSections(sections, withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.endUpdates()
}
有没有更好的方法将对象的数据映射到各个部分?我这样做的方式有效,但有点令人困惑。如果我可以使用静态视图,这会更容易,但我不能在普通 VC 中使用电视,并且您不能在其中使用静态电视。这很烦人!有更干净的方法吗?
我可以让这个更快捷 - 创建我的组合数据源的更好方法吗?
感谢您的任何建议。
我的最终结果 - 正在运行,看起来像这样 - 带有章节的 TVC。