Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:07:20+00:00 2026-05-28T04:07:20+00:00

Hi I have this code to download images from the server and then to

  • 0

Hi I have this code to download images from the server and then to show them in table view with some text (if there is no image I want to show the text anyway):

//download part

NSMutableString *photourl=[[NSMutableString alloc] initWithString:url_image];
    [photourl appendString:[dic objectForKey:@"photo"]];

    @try{

      //add to mutable array
    [photoSmallImageData addObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:photourl]]];
    }
    @catch (id Exception) {
        [photoSmallImageData addObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_image]]];

    }

//part of table view code

NSData *imageData = [photoSmallImageData objectAtIndex:indexPath.row];

    @try {

        cell.imageView.image = [UIImage imageWithData:imageData];
    }
    @catch (NSException *exception) {
      cell.imageView.image = [UIImage imageNamed:@"icon72.png"];
    }
  1. It works but the thing is sometimes there is no image so I would like to replace it with some icon but since we can’t add nil to array i juste add some part of my link there and then even if the link doesn’t work for image data it doesn’t call the catch method. I don’t know if I could some how replace the url with local url but I don’t know how. Also I can’t skip the step because then the images will not correspond to the text next to it.

2.The images are all of diferent sizes and I would like them to have standard look and be centered is there a way to do that and at which point of the code? Thank you very much

EDIT I have found the method:
dataWithContentsOfURL:options:error:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html
but I don’t know how to use it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:07:21+00:00Added an answer on May 28, 2026 at 4:07 am

    Why don’t you create the images when the image data is downloaded and keep them in the array? Also, you are right to be after the dataWithContentsOfURL:options:error: method. Given that you keep the image names in the dic dictionary, the code would look like this:

    NSMutableString *photourl=[[NSMutableString alloc] initWithString:url_image];
    [photourl appendString:[dic objectForKey:@"photo"]];
    
    //try to create the image
    NSError* err = nil;
    UIImage* img = nil;
    NSData* tempData = [NSData dataWithContentsOfURL:[NSURL URLWithString:photourl] options:NSDataReadingMappedIfSafe error:&err];
    if (!err) {
        // image data loaded, create image
        img = [UIImage imageWithData:tempData];
    } else {
        // image data could not be loaded, display error
        NSLog(@"%@", err);
        // put the default image in the array
        img = [UIImage imageNamed:@"icon72.png"];
    }
    [photoSmallImage addObject:img];
    

    And then in the table view delegate:

    cell.imageView.image = [photoSmallImage objectAtIndex:indexPath.row];
    

    As for the second part of your question, you may want to have a look at the contentMode property of UIView class. The default is scale to fill. By manipulating this property on the cell.imageView, you can achieve the effect that you desire.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing some code which will download images from my web server for
This is the code which I have been using to download images from URLs:
I have this code to download a file, but on sourceforge.net sever there is
When I have download sample code from this link and than try to build
I have an inner class that downloads some images from the server. The problem
I have this thread which downloads a few images from the server. So once
I have created a class to download images from web. Issue is there is
I have an app which downloads images from a server, stores them on the
I want to force the download of an image. I have found this code:
I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.