1

我有一个带字典的 plist。
在字典中,我有一个名为“cellPic”的字符串,其中包含图像的 url 地址。
我正在尝试使用我放在我的保管箱帐户中的图像填充我的表格视图并通过 plist 字符串读取它们。
(“arrayFromPlist”是我的数组)
问题是当我运行它时,我在控制台中收到错误:
[__NSCFDictionary objectAtIndex:]: unrecognized selector

这是我的代码:

-(void) readPlistFromDocs
{
    // Path to the plist (in the Docs)
    NSString *rootPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
    NSString *plistPath = [rootPath stringByAppendingPathComponent:@"Data.plist"];
    NSLog(@"plistPath = %@",plistPath);
    // Build the array from the plist  
    NSMutableArray *arrayFromDocs = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
if (arrayFromDocs)
{
    NSLog(@"\n content of plist file from the documents \n");
    NSLog(@"Array from Docs count = : %d", [arrayFromDocs count]);
}
    arrayFromPlist = [[NSArray alloc] initWithArray:arrayFromDocs];
}   

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

// Returns the number of rows in a given section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrayFromPlist count];
    NSLog(@"Array SIZE = %d",[arrayFromPlist count]);
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

NSURL *url = [[NSURL alloc] initWithString:[[arrayFromPlist objectAtIndex:indexPath.row] objectForKey:@"cellPic"]];
NSData *urlData = [[NSData alloc] initWithContentsOfURL:url];
[[cell imageView] setImage:[UIImage imageWithData:urlData]];

return cell;
}

我的另一个问题是 - 当我从 plist 字符串中读取 url 时,如何异步加载图像?
我试图找到一个例子,但我发现只有异步没有uisng plist。
谢谢。

4

1 回答 1

0

更改以下行

NSDictionary *arrayFromDocs = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

异步加载图像的最佳教程

希望对你有帮助..

于 2012-04-28T11:06:53.270 回答