1

我有一个由 plist 填充的 tableView。

plist 中的每个项目都有自己的 id。

plist 的结构如下:

Root    
>Item 0
   Title  (Title of the first section in the tableView)
   Rows (Array -> Rows of the first section)
     >Item 0
        id 
        name
        description
        image
     >Item 1
        id 
        name
        description
        image
      //etc

由于一张图片比 1000 字更好,这里是:

现在,我想从 detailView 访问 plist 的下一项,但我不知道该怎么做或机制应该是什么样的。我用谷歌搜索了很多来完成这个,但我没有找到任何可以真正帮助我的东西,这就是我在这里问的原因。

我已经在 detailView 中打开了 plist(从访问 id 的 tableView 打开),我想创建一个按钮或其他东西来转到下一个项目。

比如detailView是Item 0的id,我需要访问下一个id,也就是Item 1的id。

有没有人这样做过?

非常感谢您提前。

4

2 回答 2

2

这很简单,在 DetailView 中加载您的 plist,然后完成剩下的工作。

于 2013-01-16T18:11:16.667 回答
1

首先导入 plist(如果它存储在包中,则适用):

NSError *error = nil;
NSString *file  = [[NSBundle mainBundle] pathForResource:@"Name" ofType:@"plist"];
if (!file) {
        // Handle error if file not found
}

然后将文件作为字典打开(我假设您不需要初始数组):

// Open the file
NSArray *array = [NSArray arrayWithContentsOfFile:file];
NSDictionary *dictionary = [array objectAtIndex:0]; // Skipped checking if array is empty
if (!dictionary) {
        NSLog(@"Failed to process plist file");  // Handle error
}

然后您可以在字典中查询所需的对象,即在这种情况下带有键 @"MyKey" 的数组:

NSArray *rowArray= [dictionary objectForKey:@"MyKey"];

然后您可以从数组中检索下一个对象。

于 2013-01-08T22:22:51.607 回答