将多维数组中的图像加载到 UIImageView 中
我正在将图像加载到自定义单元格,并在整个代码中从 XML 构建一个数组,我想将其设置为 nib 文件上的 UIImageView。
我的数组构建为totalArray,然后我在 cellForRowAtIndexPathT 中执行以下操作:
newObj1=[totalArray objectAtIndex:indexPath.row];
aCell.lblRouteText.text = newObj1.routeText;
以下加载图像有效(静态):
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://imageurl.jpg"]]];
aCell.imgRoute.image = image;
但是,当我尝试使用以下内容放入数组时:
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[newObj1.routeImage]]];
我收到预期标识符错误
有什么建议吗?
汤姆
I'm loading an image to a custom cell and I build up an array throughout my code from XML which I want to set to my UIImageView on my nib file.
My array gets built up to totalArray and then I do the following in my cellForRowAtIndexPathT:
newObj1=[totalArray objectAtIndex:indexPath.row];
aCell.lblRouteText.text = newObj1.routeText;
And the following to load my image works (static):
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://imageurl.jpg"]]];
aCell.imgRoute.image = image;
However, when I try to put my array in using the following:
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[newObj1.routeImage]]];
I get an error of identifier expected
Any tips?
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在编写
[newObj1.routeImage]
,您只需要newObj1.routeImage
,即您的最后一行可能应该是:当您使用方括号时(而不是在上下文中) C 数组),您应该始终具有
[xy]
形式的内容,这意味着“将消息y
发送到接收者x
” '。关于线程的注意事项:使用
[NSData dataWithContentsOfURL:]
时要小心,因为它在获取 URL 内容时会阻塞。如果您在主线程上调用此方法,您将阻塞您的 UI,并且应用程序将无响应。(顺便说一句,如果您要发布错误消息,最好从控制台复制并粘贴完整的实际错误行(如果可能的话)——这样可以最大限度地提高我们理解问题的机会。)
You're writing
[newObj1.routeImage]
where you just neednewObj1.routeImage
, i.e. your final line should probably read:When you use square brackets (and not in the context of a C array), you should always have something of the form
[x y]
, which means 'send the messagey
to the receiverx
'.Note on threading: be careful about using
[NSData dataWithContentsOfURL:]
, because it blocks while the URL contents are fetched. If you call this on the main thread, you will block your UI and the app will be unresponsive.(Btw, if you're posting error messages, it's best to copy and paste the full actual error line(s) from the console if possible -- it maximises our chance of understanding the problem.)