2016-03-03 69 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