arrays - 我想将具有属性(btnImage + btnTitle)的字典数组从Plist读取到TableViewCell中

标签 arrays swift uitableview dictionary plist

Created array of dictionary having buttons.

-创建了 UITableviewcell.xib 和 .swift -创建了IB 链式IB -链接的数据源和委托(delegate) 需要进一步帮助来读取我的 plist 数据并将其显示到 tableViewCell

最佳答案

使用Decodable,非常简单

struct Section : Decodable {
    let title, icon : String
}

如果文件在 bundle 中,则将其读取为数据并对其进行解码

let url = Bundle.main.url(forResource: "sections", withExtension: "plist")!
do {
    let data = try Data(contentsOf: url)
    let result = try PropertyListDecoder().decode([Section].self, from: data)
} catch { print(error) }

结果将包含Section项的数组

关于arrays - 我想将具有属性(btnImage + btnTitle)的字典数组从Plist读取到TableViewCell中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54106230/

相关文章:

iOS 如何修复自定义 UITableView 单元格中的 UIButton 高度

java - 无效的简单日期格式 + InputMisMatch

ios - 如何为 NSAttributedString 的不同部分添加不同的行距?

swift - 无法在 Swift 中实现这种设计模式?

ios - 通知 UITableView dataSource 的变化

ios - 从一个数据源切换到另一个数据源并重新加载 UITableView 时错位或隐藏 UITableView 部分标题

javascript - 使用 push() 将对象添加到对象中

python - lexsort 负数之前的零?

c++ - 防止在 C++ 中构造/初始化数组元素

arrays - Swift:获取二维数组中最小项的索引