繁体   English   中英

分割图像网址列表后无显示

[英]Nothing displayed after splitting a list of image URLs

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

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

没有错误,但我没有图像。 为什么? 我该如何解决?

如果dataimage都不为nil ,则可以尝试正确初始化_homeImage。 我不知道为什么,但是我想您是这样创建_ homeImage的

_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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM