2011-02-09 84 views
2

我有一個.plist引用.png文件的路徑(鍵值=「maps」)。我能夠將圖像通過使用此代碼,同時加載視圖添加到一個數組:從.plist填充UIImageView

-(void)viewDidLoad { 

NSString *path = [[NSBundle mainBundle] pathForResource:@"countries" ofType:@"plist"]; 
NSArray *countries = [NSArray arrayWithContentsOfFile:path]; 
NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"maps" ascending:NO] autorelease]; 
self.sortedCountries = [countries sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]]; 

} 

我能夠使用這種方法來添加圖像TableViewCells:

-(UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath {} 

我我試圖做的是將這些相同的圖像添加到新的ViewController中的UIImageView實例。我已經正確設置了ViewController,但是我怎樣才能從UIImageView中顯示圖像,就像我爲UITableViewCells做的那樣?

回答

1

當你選擇下面的方法表中的行獲得呼叫 -

 
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    UserDetailVC* userDetailVC=[[UserDetailVC alloc] initWithNibName:@"UserDetailVC" bundle:nil]; 
    [userDetailVC autorelease]; 
    //imp- set the image over here 
     NSDictionary* tempDict=[yourArray objectAtIndex:indexPath.row]; 
     userDetailVC.selectedImageView.image=[tempDict objectForKey:@"imageName"]; 
    [self.navigationController pushViewController:userDetailVC animated:YES]; 

    return nil; 
} 

所以嘗試這樣做,這肯定會去幫助你。

+0

數組沒有`-objectForKey:`方法,更不用說`-ObjectForKey:`方法了。也許你的意思是`-objectAtIndex:`? – 2011-02-09 12:59:46