0

I use random() to make a NSMutableArray and in the NSMutableArray have NSUrl for loading image to paste on every tableview header

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"]];
smiletony
  • 5
  • 4
  • You want to download the image from the URL? if it is, check this thread http://stackoverflow.com/questions/17365135/how-to-get-image-from-server-using-nsurlconnection – Ulysses Mar 03 '16 at 03:07
  • Your question is not clear, also what do you mean by [imagearray setImageWithURL:[NSURL URLWithString:url1] placeholderImage:[UIImage imageNamed:@"video-bg.png"]]; – Bharat Modi Mar 03 '16 at 04:06

2 Answers2

0

I think r u used in the AFNetworking Image cache method, In here your mistake is

you called the setImageWithURL for NSMutableArray it is 100 % wrong .

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

you need to do like

 -(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;
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

If there were many URL's you can store in array and store objects in NSString by objectatindex

But if there is single URL so You dont need to store URL to an array. You can directly get image form url by using below function

To get image from url Declare the below Function

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

    return image;
     }

You have to store url into string like

NSString *imageurl = @"Your URLPath HERE for Image";

You have your imageview and call the below method to assign that image from url

self."Yourimageview".image=[self getImageFromURL:imageurl];

Hope this will work for you

Jitendra Modi
  • 2,344
  • 12
  • 34