iphone – iOS:从plist文件加载图像
发布时间:2020-12-15 01:47:34 所属栏目:百科 来源:网络整理
导读:我试图将plist文件中的各种图像显示到UIImageView中,我编写了这样的代码: NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Photos" ofType:@"plist"]]; imageArray = [picturesD
我试图将plist文件中的各种图像显示到UIImageView中,我编写了这样的代码:
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Photos" ofType:@"plist"]]; imageArray = [picturesDictionary objectForKey:@"PhotosArray"]; PhotosInAlbum.image = [UIImage imageWithContentsOfFile:[imageArray objectAtIndex:1]]; 但实际上没有任何反应,我的ImageView是空的!我也有两个按钮来转发后向图像. Plist的内容: 解决方法
plist是不正确的,它应该是
Root ---- Dictionary PhotosArray ----- Array Item 0 ------ String -- Beach.jpg 然后将此代码添加到viewController中.确保Interface imageView链接到IBOutlet. NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Photos" ofType:@"plist"]]; NSArray *imageArray = [picturesDictionary objectForKey:@"PhotosArray"]; PhotosInAlbum.image = [UIImage imageNamed:[imageArray objectAtIndex:0]]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |