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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:41:30+00:00 2026-05-28T18:41:30+00:00

I have a method I am calling from my mainview that is setting the

  • 0

I have a method I am calling from my mainview that is setting the image name of the image I want to display in a scrollview.

 - (void)loadImage:(NSString *)myImageName
    {
        if (myImageName == @"one") {
            imageName = myImageName;
        }
        if (myImageName == @"two") {
            imageName = myImageName;
        }
        if (myImageName == @"three") {
            imageName = myImageName;
        }

        //Reloads view here???
    }

I am loading the images in my viewdidload method like so

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Create scrollview
    scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    scrollView.delegate = self;
    scrollView.bounces = NO;

    //Create scrollviewimage
    if (imageName == @"one") {
        image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ha.png"]];
    }
    if (imageName == @"two") {
        image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"haha.png"]];
    }
    if (imageName == @"three") {
        image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hahaha.png"]];
    }



    containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 550)];
    //Add subview
    [containerView addSubview:image];
    //initViews
    scrollView.contentSize = containerView.frame.size;
    [scrollView addSubview:containerView];

    //scrolling
    scrollView.minimumZoomScale = 1.0;
    scrollView.maximumZoomScale = 31.0;
    [scrollView setZoomScale:scrollView.minimumZoomScale];

    //highrachy
    [self.view addSubview:scrollView];

}

What happens when I set the imagename from the parentview from a tableviewcell selection I pass down the nsstring into loadImage.. then load image sets the name in viewdidload.. however what is happening is that only the first selection dose anything.. so you will always see the first image you are selecting.. so if you pick image two every other image you select will show image two..

any help would be great.

here is what the parentview cell selection looks like

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];

    if (!self.detailViewController) {
        self.detailViewController = [[ICDDetailViewController alloc] initWithNibName:@"ICDDetailViewController" bundle:nil];

        if (indexPath.section == 0) {
            _detailViewController.imageName = @"one";
            //        NSLog(@"%@", indexPath);
        }
        if (indexPath.section == 1) {
            _detailViewController.imageName = @"two";
            //        NSLog(@"%@", indexPath);
        }
        if (indexPath.section == 2) {
            _detailViewController.imageName = @"three";
            //        NSLog(@"%@", indexPath);
        }
    }
    [self.navigationController pushViewController:self.detailViewController animated:YES];

}
  • 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-28T18:41:31+00:00Added an answer on May 28, 2026 at 6:41 pm

    Don’t use myImageName == @”three”. There’s a special method for comparing strings.

    try this:

    if ([myImageName isEqualToString:@"three"]) {
        [image setImage:[UIImage imageNamed:myImageName]];
    }
    

    If there is a file extension, do this:

    NSString *imagePath = [NSString stringWithFormat:@"%@.png",myImageName];
    [image setImage:[UIImage imageNamed:imagePath]];
    

    By the way, you are still posting the old code you had in your other question. You are retaining your detailView in your original class instead of releasing and creating a new instance. Take out the if (!detailView) statements.

    Update: the only other option is to take the assignments out of the large if( ) block.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];
    
        if (!self.detailViewController) {
            self.detailViewController = [[ICDDetailViewController alloc] initWithNibName:@"ICDDetailViewController" bundle:nil];
    
    
        //MY CHANGES HERE:
        //If you left these if () statements inside the original code, they would never
        //fire if the detailView was already instantiated once.  Does this make sense?
        }  // <--- moved the bracket up here
            if (indexPath.section == 0) {
                _detailViewController.imageName = @"one";
                //        NSLog(@"%@", indexPath);
            }
            if (indexPath.section == 1) {
                _detailViewController.imageName = @"two";
                //        NSLog(@"%@", indexPath);
            }
            if (indexPath.section == 2) {
                _detailViewController.imageName = @"three";
                //        NSLog(@"%@", indexPath);
            }
        //}  <--- commented this one out
        [self.navigationController pushViewController:self.detailViewController animated:YES];
    
    }
    

    The only other way is this:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];
        //commented out the next line, don't need to check to see if it's already present
        //just create a new instance to push on the stack
        //if (!self.detailViewController) {
            self.detailViewController = [[ICDDetailViewController alloc] initWithNibName:@"ICDDetailViewController" bundle:nil];
    
            if (indexPath.section == 0) {
                _detailViewController.imageName = @"one";
                //        NSLog(@"%@", indexPath);
            }
            if (indexPath.section == 1) {
                _detailViewController.imageName = @"two";
                //        NSLog(@"%@", indexPath);
            }
            if (indexPath.section == 2) {
                _detailViewController.imageName = @"three";
                //        NSLog(@"%@", indexPath);
            }
        //} <--- get rid of this bracket since the original if () was commented out
        [self.navigationController pushViewController:self.detailViewController animated:YES];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following delegate delegate void UpdateFileDelegate(long maxFileID); That I am calling from
I have a destroy method within a notecards controller that I am calling from
Possible Duplicate: Retrieving the calling method name from within a method (C#) I have
I have a method that I'm writing that is calling another overloaded method inside
I have a controller method that returns a jSON object and in one calling
I know that I should have schema of a table before calling NewRow method
I have a method called Rotate and I am calling it from another method
I have two test method calling to controller: This one passed: [Test] public void
i have trouble with calling method from another class this is my code this
I have a snippet of code that I'm calling from a service: context.registerReceiver(new BroadcastReceiver()

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.