2011-02-09 58 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