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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:33+00:00 2026-05-27T18:48:33+00:00

I am trying to create a sort of ‘settings’ page, and I am having

  • 0

I am trying to create a sort of ‘settings’ page, and I am having a hard time switching the background image of my original view. The code, so far, is:

-(IBAction)switchBackground:(id)sender {
ViewController *mainView = [[ViewController alloc] initWithNibName:nil bundle:nil];
mainView.displayedImage.image = [UIImage imageNamed:@"image.png"];;
}

Perhaps I can get some pointers?

Thanks, all.

  • 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-27T18:48:33+00:00Added an answer on May 27, 2026 at 6:48 pm

    You are creating a new mainView object each time you call switchBackground method. You must change the background of an existing object to see the change happen.

    From your code it is hard to say where switchBackground method is located. ViewController?

    If it is located in the view controller then all you have to do is:

    self.displayedImage.image = [UIImage imageNamed:@"image.png"];
    

    EDIT

    As per your comment.

    When you want to change the image of an object of class A from class B you can do it in two different ways:

    1. Through reference to an object

    this is the settings initializer which on creation gets the pointer to your existing mainView

    @property(nonatomic,assign)ViewController *mainView;
    
    - (id)initWithMainViewController:(ViewController*)vc {
        self = [super init];
        if (self) {
            self.mainView = vc;
        }
        return self;
    }
    
    -(IBAction)switchBackground:(id)sender {
        mainView.displayedImage.image = [UIImage imageNamed:@"image.png"];
    }
    

    2. By posting local notification through NSNotificationCenter.

    -(IBAction)switchBackground:(id)sender {
          [[NSNotificationCenter defaultCenter] postNotificationName: @"changeImage" object: [UIImage imageNamed:@"image.png"]];
    }
    

    Now in your ViewController listen to the notification and react

    in the init method in ViewController

    - (id)initWithMainViewController:(ViewController*)vc {
        self = [super init];
        if (self) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeImage:) name:@"changeImage" object:nil];
        }
        return self;
    }
    
    -(void)changeImage:(NSNotification*)notification{
        self.displayedImage.image = (UIImage*) notification.object;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create some sort of timeline view like in video editors: media
I'm trying to create this sort of pop up action sheet view similar to
I'm trying to create an array, and then sort the objects by time, from
Basically I am trying to create a sort of product image gallery lightbox thing.
I am trying to create and initialize some sort of master view model that
I am trying to create a sort of a window, formed by multiple divs.
I have been trying to create a ListView which I can sort using drag
I'm sort of new to c++ and i'm trying to create a game. I
I'm trying to create an Advanced Searching form that sort of look like this
Basically I'm trying to create a BASIC sorting program in ruby without using .sort

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.