【问题标题】:why images are not loading from local XMl file in iphone为什么图像没有从 iphone 中的本地 XML 文件加载
【发布时间】:2012-11-22 12:31:19
【问题描述】:

像这样从本地 XML 文件加载图像时,

<?xml version="1.0" encoding="UTF-8"?>
<Books>
<book id="1">
<img>/Users/admin/imagefolder/Main_pic.png</img>
</book>
</Books>

正在解析文件并从文件中解析图像。我可以在 NSLog 输出中看到

<UIImage: 0x71883d0>

但是当我在 iphone 中以 UIImage 视图查看它时,没有显示图像。我已经像这样在 viewDidLoad 方法中设置了图像,

- (void)viewDidLoad{
        [super viewDidLoad];
        app = [[UIApplication sharedApplication]delegate];
        UIImage *image = [UIImage imageWithContentsOfFile:@"/Users/admin/imagefolder/Main_pic.png"];
       [theLists setImg:image];
   }

哪里做错了?如何在iphone的UIImageView中获取图像作为输出

已编辑:

“theLists”是我定义了 UIImage 对象的文件的对象说我有一个像这样的文件“list.h”,我在其中定义图像

@interface list : NSObject
@property(nonatomic,retain) UIImage *img;

现在在 appdelegate.m 文件中导入“list.h”并像这样使用,

@property(nonatomic,retain) list *theLists;

这个“thelists”在viewDidLoad()中使用

Edited-2

我的解析代码在这里,

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sample.xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
 NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
 egsParser *theParser =[[egsParser alloc] initParser];
[xmlParser setDelegate:theParser];

【问题讨论】:

  • 您是如何在视图中添加列表的?检查 IB 是否正确连接到图像视图。
  • 如何将您的列表添加到视图中?
  • 您确定您使用的是 iOS 吗?沙盒
  • 请提供有关列表对象和类的更多信息。
  • 什么是 theLists ,您如何将其添加到您的视图中,您正在调用的目录在哪里,以及您如何显示日志。

标签: iphone ios


【解决方案1】:

如果您的图像存储在数组中,您应该使用如下代码:

UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@",(((list *)[yourImagesArray objectAtIndex:i]).img)]];

如果您将数据存储为NSString,则访问您的数据。 数组中图像的 i 个数

 UIImage *image = (((list *)[yourImagesArray objectAtIndex:i]).img);

如果你喜欢UIImage

【讨论】:

  • 我不明白你发布的如何使用它,但我在我的代码中复制了这些,它符合错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-11
  • 2011-04-24
  • 1970-01-01
  • 2017-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多