2016-03-03 72 views
0
加载URL

我使用随机的()做出的NSMutableArray,并在NSMutableArray中有NSURL加载图像上每一个tableview中头我怎么会从NSArray中

NSMutableArray *imagearray = [[NSMutableArray alloc]init]; 

for (int i = 0;i < 10; i++) 
{ 
    [imagearray addObject:[NSString stringWithFormat:@"http://flicksbank.console360.net/images/%@/default.jpg",randomArray[i][@"id"]]]; 
} 

[imagearray setImageWithURL:[NSURL URLWithString:url1] placeholderImage:[UIImage imageNamed:@"video-bg.png"]]; 
+0

你想从URL下载图像工作?如果是这样,检查这个线程http://stackoverflow.com/questions/17365135/how-to-get-image-from-server-using-nsurlconnection – UlyssesR

+0

你的问题不清楚,你也是什么意思[imagearray setImageWithURL :[NSURL URLWithString:url1] placeholderImage:[UIImage imageNamed:@“video-bg.png”]]; –

回答

0

贴我认为在AFNetworking图像缓存使用RU方法,在这里你的错误是

你叫setImageWithURLNSMutableArray它是100%错误。

[imagearray setImageWithURL:[NSURL URLWithString:url1] placeholderImage:[UIImage imageNamed:@"video-bg.png"]]; 

你需要做的像

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *teamview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)]; 
    /* Create custom view to display section header... */ 
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)]; 
     [imageView setImageWithURL:[NSURL URLWithString:url1] placeholderImage:[UIImage imageNamed:@"video-bg.png"]]; 
    [teamview addSubview:imageView]; 
    [teamview setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color... 
    return teamview; 
} 
+0

其实它是SDWebimage无论如何它的固定感谢 – smiletony

+0

欢迎我的兄弟.. –

0

如果有很多的URL,你可以在NSString的阵列和存储对象存储由objectatindex

但如果有一个网址,以便您不需要将URL存储到数组中。您可以通过以下功能

要想从URL图像声明如下功能

-(UIImage *) getImageFromURL:(NSString *)fileURL { 
    NSURL *url = [NSURL URLWithString: 
        fileURL]; 
    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; 

    return image; 
    } 

你要的网址保存到字符串如

直接获得的图像格式网址

NSString * imageurl = @“Your URLPath HERE r Image“;

你有你的ImageView并调用下面的方法,以该图像从URL指定

自我 “Yourimageview”=图像配[自getImageFromURL:IMAGEURL]。

希望这会为你

+0

感谢您的帮助~~~ – smiletony