SWIFT 属性列表 : From TableView to DetailView plist

标签 swift uitableview swift2 tableview plist

第一次使用plist。只是尝试寻找一些使用字典/数组的替代方法。我有以下由 plist 填充的表格 View 。

enter image description here

Plist 帮助

plist 还可以允许我单击 plist 上的各个项目并显示 plist 中的一些数据吗?或没有?还没有真正发现任何东西。非常感谢所有帮助和提示。

我正在尝试做的事情的示例: https://www.youtube.com/watch?v=cIUnYwbtSDg

TableViewController

class TableViewController: UITableViewController {
var tableData = [String]()

override func viewDidLoad() {
    super.viewDidLoad()
    
    let path = NSBundle.mainBundle().pathForResource("TableData", ofType: "plist")
    let dict = NSDictionary(contentsOfFile: path!)
    
    tableData = dict!.objectForKey("AppleDevice") as! [String]

最佳答案

请找到下面的屏幕截图。

enter image description here

如屏幕截图所示,只需单击 .plist 文件 -> 打开为 -> 属性列表,它将以您在 YouTube 视频中提到的属性列表方式显示。

更新

请考虑您的 .plist 数据,找到以下示例:

let detailController = self.storyboard?.instantiateViewControllerWithIdentifier("detailViewController") as? DetailViewController

tableData = dict!.objectForKey("AppleDevice") as! [String]
detailController.detailInfo = tableData

您可以使用另一个 View Controller 名称来代替 DetailViewController。

在 DetailViewController 类中:

class DetailViewController: UIViewController {

    var detailInfo: [String]? {
        didSet {
            // Update the view.
            print("Detail Information",detailInfo)

            //Now here you can display the data in any UI component like UITextView.
        }
    }
}

希望它对你有用!

关于SWIFT 属性列表 : From TableView to DetailView plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35282991/

相关文章:

iOS - UIWebview 在滚动时部分消失

swift - 为什么没有为可选数组定义 Equatable

swift - 移动时将球体附加到设备屏幕的中心

iOS:如何在 Framework 中添加 Assets 文件夹以及如何在代码中访问它们?

ios - 如何设计一个带有复杂 TableView 的 ViewController

iphone - 我可以在 fetchedResultsController 中使用多个sectionNameKeyPath吗?

swift - 命令编译 Storyboard 失败,退出代码非零

ios - 为所有页面添加导航栏和标签栏

ios - Heimdall Swift 验证每个请求失败

ios - 选择后从 UIPicker 中删除字符串