我正在创建一个包含大量静态数据的应用程序。数据由图像和文本组成(每个文本文件由多个字符串组成),它将是项目的数据。我有这样的文件夹排序:
- Category
- - Name 1
- - - Image1.png, text1.strings
- - Name 2
- - - Image2.png, text2.strings
然后我想在tableview中将该类别的每个文件夹显示为自己的行。这是一种不好的方式吗,还有其他任何一种首选方法吗?如果不是如何在Xcode中使用Swift执行此操作?
也可以在将来进行搜索吗?
答案 0 :(得分:2)
cell.indentationLevel = 1 // Your indentation level
<强>更新强>
@IBOutlet weak var tblView: UITableView!
let tblData:[[String:Any]] = [["title":"Category", "indentationLevel":0],
["title":"Name 1", "indentationLevel":1],
["title":"Image1.png", "indentationLevel":2],
["title":"Name 2", "indentationLevel":1],
["title":"Image2.png", "indentationLevel":2]]
// UITableView delegate methods
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tblData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
cell?.textLabel?.text = tblData[indexPath.row]["title"] as? String ?? "NA"
cell?.indentationWidth = 10
cell?.indentationLevel = tblData[indexPath.row]["indentationLevel"] as? Int ?? 0
return cell!
}
注意:强>
您可以使用plist存储静态数据而不是字典数组