【发布时间】:2020-06-02 09:33:08
【问题描述】:
嗨,我想制作一个如下图所示的视图,所以我尝试用 UITableViewCell 和一个字符串制作一个二维数组。由于它是 Any 类型,因此编译器会抱怨“Type Any 没有 count 和 subscript 的成员”。我的方法对吗?使这个视图像下图一样,还是我应该一个一个地创建?
这是我的代码
var tableItems = [
[ProgressCell.self],
["Information", "Address", "Password"],
["Help", "Term and Condition", "Privacy"],
[SignOutCell]
] as Any
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableItems[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)
let name = tableItems[indexPath.section][indexPath.row] as! Int
cell.textLabel?.text = name
cell.textLabel?.font = UIFont(name: "NunitoSans-Regular", size: 16)
cell.accessoryType = .disclosureIndicator
return cell
}
【问题讨论】:
标签: ios arrays swift uitableview multidimensional-array