gpt4 book ai didi

iphone - 从 .plist 填充 UIImageView

转载 作者:行者123 更新时间:2023-12-03 21:20:55 26 4
gpt4 key购买 nike

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

-(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,但是如何像我对 UITableViewCells 所做的那样从数组中提取图像并显示在 UIImageView 中?

最佳答案

当您选择表中的行时,将调用以下方法 -

- (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;}

所以尝试一下,这肯定会对你有帮助。

关于iphone - 从 .plist 填充 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com