从.plist填充UIImageView

时间:2011-02-09 12:52:54

标签: iphone objective-c uiviewcontroller uiimageview plist

我有一个引用.png文件路径的.plist(键值=“地图”)。我可以在加载视图时使用此代码将图像添加到数组中:

-(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 个答案:

答案 0 :(得分: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;
}

所以试过这个,这肯定会帮助你。