Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Read&;使用Xcode编写包含字典数组的Plist_Xcode_Nsmutablearray_Plist_Nsmutabledictionary - Fatal编程技术网

Read&;使用Xcode编写包含字典数组的Plist

Read&;使用Xcode编写包含字典数组的Plist,xcode,nsmutablearray,plist,nsmutabledictionary,Xcode,Nsmutablearray,Plist,Nsmutabledictionary,这是我的问题,我正在尝试创建一个UITableView,它能够在单元格中显示plist中的名称。我无法从名单上查到名字。我想我对提取信息所需的编程代码不是很确定 如果你能提供一个很好的教程或示例代码来帮助我,那就太好了。谢谢 <array> <dict> <key>Name</key> <string>Device 2</string> </dict> &l

这是我的问题,我正在尝试创建一个UITableView,它能够在单元格中显示plist中的名称。我无法从名单上查到名字。我想我对提取信息所需的编程代码不是很确定

如果你能提供一个很好的教程或示例代码来帮助我,那就太好了。谢谢

<array>
    <dict>
        <key>Name</key>
        <string>Device 2</string>
    </dict>
    <dict>
        <key>Name</key>
        <string>Device 1</string>
    </dict>
</array>
在我的桌面视图中

static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]autorelease];
    }

    cell.textLabel.text = [sortedArray objectForKey:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;

也许您想在viewDidLoad中尝试以下内容:

NSBundle *bundle = [NSBundle mainBundle];

    NSString *path = [bundle pathForResource:@"devicelist" ofType:@"plist"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        NSLog(@"The file exists");

    self.contentArray = [NSMutableArray arrayWithContentsOfFile:path];
    NSLog(@"The array: %i", [contentArray count]);

    [mainTableView reloadData];
}
请注意,contentArray应该是一个retain属性,然后在CellForRowatineXpath方法中:

NSDictionary *dict = [self.contentArray objectAtIndex:indexPath.row];
cell.textLabel.text = (NSString*)[dict objectForKey:@"Name"];

希望这对您有所帮助……

也许您想在viewDidLoad中尝试以下内容:

NSBundle *bundle = [NSBundle mainBundle];

    NSString *path = [bundle pathForResource:@"devicelist" ofType:@"plist"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        NSLog(@"The file exists");

    self.contentArray = [NSMutableArray arrayWithContentsOfFile:path];
    NSLog(@"The array: %i", [contentArray count]);

    [mainTableView reloadData];
}
请注意,contentArray应该是一个retain属性,然后在CellForRowatineXpath方法中:

NSDictionary *dict = [self.contentArray objectAtIndex:indexPath.row];
cell.textLabel.text = (NSString*)[dict objectForKey:@"Name"];
希望这有助于