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 6634835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:58:37+00:00 2026-05-25T22:58:37+00:00

I know this question has been asked and answered in other forums, but I

  • 0

I know this question has been asked and answered in other forums, but I can’t seem to duplicate what they did and get it to work. I am trying to set the background to a button using a picture that I download from a server. Everything works until I try to make a NSData object with the contents of a URL. When I try and print the Data to the screen it comes back Null. What am I doing wrong?

myImageURLString = [[NSMutableString alloc] initWithString:@"http://destinationnexus.com"];
    keyName = [businessButtonTagArray objectAtIndex:i];
    arrayFromBusinessDictionary = [businessDictionary objectForKey:keyName];
    stringToAddToMyImageURLString = [arrayFromBusinessDictionary objectAtIndex:1];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [button setTag:i];  
    button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 155);

    [myImageURLString appendString:stringToAddToMyImageURLString];
    NSLog(@"Appended URL String: = %@", myImageURLString);


    NSURL *myImageURL = [NSURL URLWithString:@"http://destinationnexus.com/pictures/directory/ColdWater-Inn-in-Tuscumbia-Alabama-35674-8729//.jpg"];
    NSLog(@"NSURL = %@", myImageURL);
    //THIS IS WHERE I SEEM TO HAVE A PROBLEM.....
    NSData *imageData = [[NSData alloc] initWithContentsOfURL:myImageURL];
    UIImage *image = [[UIImage alloc] initWithData:imageData] ;
    NSLog(@"Image Data = %@", imageData);
    //UIImage *myImage = [UIImage imageWithData:imageData] ; 
    [button setBackgroundImage:image forState:UIControlStateNormal];

When I run the program this is what it outputs in the Log:

Appended URL String: = http://destinationnexus.com/pictures/directory/Auburn-University-Hotel-and-Center-in-Auburn-Alabama-36830-5429.jpg

NSURL = http://destinationnexus.com/pictures/directory/ColdWater-Inn-in-Tuscumbia-Alabama-35674-8729.jpg

Image Data = (null)

  • 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-25T22:58:37+00:00Added an answer on May 25, 2026 at 10:58 pm

    You should correct your myImageURL, by deleting 2 slashes at the end of URL.

    The code goes something like this.

    NSURL *myImageURL = [NSURL URLWithString:@"http://destinationnexus.com/pictures/directory/ColdWater-Inn-in-Tuscumbia-Alabama-35674-8729.jpg"];
    NSData *imageData = [[NSData alloc] initWithContentsOfURL:myImageURL];
    UIImage *image = [[UIImage alloc] initWithData:imageData] ;
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [image release];
    [imageData release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked before numorous times but they seem to
I know this question has been asked/answered but I can't find it for the
I know this question has been asked several times, but I can't quite seem
I know this question has been asked before, but I can't seem to get
I know this type of question has been asked and answered before but I
Yes, I know this question has been asked before, but I can't find an
I know this question has been asked before, but I tried eveything and can't
I know this question has been asked before but the solutions did not work
I know this question has been asked multiple times but all the answers seem
I know this question has been asked and answered many times. But almost all

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.