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

  • Home
  • SEARCH
  • 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 571175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:28:46+00:00 2026-05-13T13:28:46+00:00

The user can choose whether he wants to use an existing image or take

  • 0

The user can choose whether he wants to use an existing image or take a new one for use as the background.

Everything works as far as the FirstViewController is concerned. Sadly the image is no longer set as the background, when the SecondViewController is displayed.

How do I enable the use of the image as background for the SecondViewController?

I used this piece of code (in the SecondViewController):

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
int bla = [prefs integerForKey:@"background_key"];
if (bla == 1) {
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1.mac.jpg"]];
} else if (bla == 2) {
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"black.jpg"]];
} else if (bla == 3) {
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pinn.png"]];
} else if (bla == 4) {
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"MyImage.png"]];
}

I tried to save the chosen image as “MyImage.png” but it looks as though it did not work. The background is black instead of the image selected.

I used this code (from the 1stViewController) to save the chosen picture as “MyImage.png”:

- (void)imagePickerController:(UIImagePickerController *)picker 
    didFinishPickingMediaWithInfo:(NSDictionary *)anInfo {

//UIImage *selectedImage;
NSURL *mediaUrl;

mediaUrl = (NSURL *)[anInfo valueForKey:UIImagePickerControllerMediaURL];
if (mediaUrl == nil)
{
    selectedImage = (UIImage *) [anInfo valueForKey:UIImagePickerControllerEditedImage];
    if (selectedImage == nil)
    {
        selectedImage = (UIImage *) [anInfo valueForKey:UIImagePickerControllerOriginalImage];
        NSLog(@"Original image picked.");
    }
    else
    {
        NSLog(@"Edited image picked.");
    }
}

[picker dismissModalViewControllerAnimated:YES];
if (selectedImage != nil)
{
    self.view.backgroundColor = [UIColor colorWithPatternImage:selectedImage];
}

// Get the image from the result
UIImage* ownImage = [anInfo valueForKey:UIImagePickerControllerOriginalImage];

// Get the data for the image as a PNG
NSData* imageData = UIImagePNGRepresentation(ownImage);

// Give a name to the file
NSString* imageName = @"MyImage.png";

// Now, we have to find the documents directory so we can save it
// Note that you might want to save it elsewhere, like the cache directory,
// or something similar.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];

// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];

// and then we write it out
[imageData writeToFile:fullPathToFile atomically:NO];

return;
}

There must be a mistake or logical mistake.
Help would be appreciated!

  • 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-13T13:28:46+00:00Added an answer on May 13, 2026 at 1:28 pm

    ImageNamed is generally used to load images that are included as part of the resources of an application.

    I suspect you want:

    UIImage* image = [UIImage imageWithContentsOfFile:fileNameAndPath];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of cities, and i want a user can choose one
In my app, the user can choose to display any number of objects onto
I need to generate a report where the user can choose All Issues, Open
I have the following list of time zones that a user can choose from,
My application supports internationalization and localization, each user can choose his preference language and
I have a MOSS workflow where on the first form, the user can choose
I have a need for unique reusable ids. The user can choose his own
Hi I am working on a program where the user can take screenshots. The
I have a screen in which a user can choose a set of meals
I am successfully posting to Facebook wall, but I want that user can choose

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.