Dog*_*fee 6 uitableview multidimensional-array ios swift
我无法找到更好的方法来做到这一点.我将学生对象的所有属性映射到2D数组.所以我的电视有部分.
我也不能使用静态表视图,如果是这样,这个问题就不存在了.
所以我在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
Run Code Online (Sandbox Code Playgroud)
//从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()
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法将对象的数据映射到部分?我这样做的方式有效,但有点令人困惑.如果我可以使用静态视图,这将更容易,但我不能在普通VC中使用电视放映,你不能在这些中使用静态电视.哪个很烦人!有更干净的方式吗?
我可以使其更加SWIFTY - 创建我的组合数据源的更好方法.
谢谢你的建议.
我的最终结果 - 工作看起来像这样 - 一个带有部分的TVC.

小智 1
我不完全确定你在问什么。“组合”有什么用?
如果您只想以更简洁的方式打包数据,Swift 中的结构非常适合此目的。就像是:
struct EmergencySection{
var name: String!
var phone: String!
}
//then to instantiate in loadDisplayDataSource
var emergencySection = EmergencySection(name: "", phone: "")
combo.append(emergencySection)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1204 次 |
| 最近记录: |