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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:20:50+00:00 2026-05-27T08:20:50+00:00

I am trying to set up something where the IBAction from view controller 1

  • 0

I am trying to set up something where the IBAction from view controller 1 would set the ImageView image in View Controller 2's viewDidLoad using tags to differentiate between the buttons pressed…. Something like (not exact code…just hashing it out in my head):

In View Controller 1:

-(IBAction)buttonpressed:(id)sender {

if (button.tag == 1) {

ViewController2ImageView.image = [UIImage imageNamed:@"image1.png"];

}else if (button.tag == 2) {

ViewController2ImageView.image = [UIImage imageNamed:@"image2.png"];
}

In View Controller 2:

-(void)viewDidLoad {

ViewController2ImageView.image = [UIImage imageNamed:@"?.png"];
}

The issue would be how to get the info from the IBAction to pass to the second view controller and having the viewDidLoad method load the correct image.

Ive seen examples converting data to NSString and passing it that way however I was really wondering if there was a better way to go about this.

Ive been able to Google my way through putting a few apps together so far however this has had me scratching my head for a few days now.

Any help or suggested code would be helpful! Even if its just a push in the right direction.

Thanks!

  • 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-27T08:20:50+00:00Added an answer on May 27, 2026 at 8:20 am

    When the button is pressed in viewController1, do something like this:

    -(IBAction)buttonpressed:(id)sender {
        if (button.tag == 1) {
            [[NSUserDefaults standardUserDefaults] setObject:@"image1.png" 
                forKey:@"viewController2SelectedImageKey"];
        } else if (button.tag == 2) {
            [[NSUserDefaults standardUserDefaults] setObject:@"image2.png" 
                forKey:@"viewController2SelectedImageKey"];
        } else {
            //set some default string for the image
            [[NSUserDefaults standardUserDefaults] setObject:@"yourDefaultImage.png" 
                forKey:@"viewController2SelectedImageKey"];
        }
    }
    

    Then in your viewDidLoad method in viewController2 do something like this:

    - (void)viewDidLoad {
        ViewController2ImageView.image = [UIImage imageNamed:[[NSUserDefaults 
            standardUserDefaults] objectForKey:@"viewController2SelectedImageKey"]];
        //other setup
    }
    

    This code sets a string to a key in the NSUserDefaults plist (the key I used is @”viewController2SelectedImageKey” but you can use any string you like), which is referenced by viewController2 upon its viewDidLoad method and uses the string as the name of the image file.

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

Sidebar

Related Questions

Is it possible to set for(AssociatedControlID) attribute using jQuery? I am trying something like
I'm trying to set up something in SDL [in C++] where I can draw
I'm trying to set a function to do something like this def __binaryTreeInsert(self, toInsert,
I'm trying to multithread something and i have my program set up such that
Trying to set up caching on our datasets - we're using clr stored procedures
I'm trying to set something up so my main dialog has one or more
I'm trying to set up capistrano for pushing my project, using git as VCS.
I'm trying to set an ambiguous variable on a class. Something along these lines:
I'm trying to set a JPEG file's image orientation in ImageMagick, but not seeing
i'm currently trying to set up something like this: a server side windows wcf

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.