2012-04-28 31 views
1

我有一本詞典的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。
謝謝。

回答