Read&;使用Xcode编写包含字典数组的Plist
这是我的问题,我正在尝试创建一个UITableView,它能够在单元格中显示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
<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"];
希望这有助于