阅读来自plist字符串的url图像

问题描述:

我有一本词典的plist。
在字典中我有一个名为“cellPic”的字符串,它具有图像的URL地址。
我想填充我的表格视图与图像,我把我的保管箱帐户&阅读他们通过plist字符串。
(“arrayFromPlist”是我的阵列)
的问题是,当我运行它,我得到在控制台一个错误:
[__NSCFDictionary objectAtIndex:]:无法识别选择阅读来自plist字符串的url图像

这是我的代码:

-(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。
谢谢。

更改以下行

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

Best Tutorial for load the images asynchronous

希望,这将帮助你..