拆分图像 URL 列表后不显示任何内容 [英] Nothing displayed after splitting a list of image URLs

查看:41
本文介绍了拆分图像 URL 列表后不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为 aux 的字符串中有六个图像 URL.我用换行符分隔的组件拆分它.我想从 aux 中一张一张地选择图像,并在 ImageView 中显示每个图像.我的代码是:

I have six image URLs in a string named aux. I split it with component separated by newlines. I want to pick images one by one from aux and display each in an ImageView. My code is:

aux = [_homeText.text stringByAppendingString:[NSString stringWithFormat:@" %@  ",item.shortDescription]];
[_homeText setText:aux];  
NSString *list =aux;
NSArray *listItems = [list componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
[listItems count];
if ([listItems objectAtIndex:0]) {
        NSURL *url = [NSURL URLWithString:aux];
            /*UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"hai" message:aux delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
                [alert show];
                [alert release];*/          
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *image = [[UIImage alloc] initWithData:data]; 
        [_homeImage setImage:image];
}
else if ([listItems objectAtIndex:1])
{
            NSURL *url = [NSURL URLWithString:aux];
            NSData *data = [NSData dataWithContentsOfURL:url];
            UIImage *image = [[UIImage alloc] initWithData:data]; 
            [_homeImage setImage:image];
}

没有错误,但我没有得到图像.为什么?我该如何解决这个问题?

There is no error but I get no image. Why? How do I fix this?

推荐答案

如果 dataimage 都不是 nil,您可以尝试正确初始化_homeImage.我不知道为什么,但我认为你像这样创建了 _homeImage:

If both data and image not nil, you may try to correctly initialize _homeImage. I don'w know why, but I think what you created _homeImage like this:

_homeImage = [[UIImageView alloc] init];

尝试做这样的事情:

CGSize imageSize = [image size];
[_homeImage setFrame:CGRectMake([_homeImage frame].origin.x, 
                                [_homeImage frame].origin.y, 
                                imageSize.width, imageSize.height)];
[_homeImage setImage:image];
[image release], image = nil;

这篇关于拆分图像 URL 列表后不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆