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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:36:05+00:00 2026-05-28T19:36:05+00:00

In my project I am using the UIIamgepickercontroller to select an image from the

  • 0

In my project I am using the UIIamgepickercontroller to select an image from the library and load it into a UIImageView. I am doing this for 2 images so I have two buttons for each image view, but I do not want to replicate the code for image picker twice and I’m not sure how to implement so that the method knows which image view to load the image into. I think I need to use button tags? but can’t find the right method.

here’s my code:

.h

`#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface LoadViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
    IBOutlet UIImageView *imageView;
    IBOutlet UIImageView *imageView2;
}

- (IBAction)pick1;
- (IBAction)pick2; 
- (void) getImage;


@end`

.m

#import "LoadViewController.h"

@implementation LoadViewController

UIImage *imageHandle;

- (IBAction)pick2 {

    [self getImage];
    imageView2.image = imageHandle;
}

- (IBAction)pick1{

    [self getImage];
    imageView.image = imageHandle;
}

- (void)getImage {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];

}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    imageHandle = image;
    [picker.parentViewController dismissModalViewControllerAnimated:YES];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker.parentViewController dismissModalViewControllerAnimated:YES];
}

@end

Another problem I’v been having is that the methods to catch whether I have selected an image or cancelled the view do not seem to work although if I comment out the entire method (void)imagePickerControllerDidCancel then it will cancel?!?

I’m in the early stages of learning this stuff and any help would be very much appreciated!

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-28T19:36:06+00:00Added an answer on May 28, 2026 at 7:36 pm

    You can identify the button with a tag (you can set this in Interface Builder), which is an arbitrary integer. The problem is that you’ve rejected the chance to receive a reference to the sender (the button); instead of - (IBAction)pick1, say - (IBAction)pick1:(id)sender. Now you can check the sender’s tag (cast the sender to a UIView* so the compiler understands what you’re doing).

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

Sidebar

Related Questions

I have a project using ASIHTTP to multi download files from a site when
I have an project using Hibernate. This has a class named Question . Each
I m doing a project using eclipse plugin to create a IDE. I have
I have compiled a project using Eclipse with C/C++ plugin (using http://libcinder.org library, and
I am creating a project using WPF and MVVM-Light library from GalaSoft. I will
I have a test project using MbUnit and TestDriven.Net. If I right-click on an
I have deploy my project using project:deploy --go. Now i have my folders apps,
I have a project using StoryBoards and UISearchDisplayController used in the context of a
I'm creating a project using Django. For this project I use git and redmine
I am doing a project using TranslateAnimation in Android. In that I am translating

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.