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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:32:40+00:00 2026-05-12T12:32:40+00:00

I am attempting to allow a user to select an image from the photo

  • 0

I am attempting to allow a user to select an image from the photo gallery and assign a comment to it.

The photo class presents a UIIMagePickerController and I am able to successfully retain the image chosen by the user. However, when I create a view controller for the comment box and present/dismiss it, I am not sure how to save the value of the text the user entered because that value is declared in a separate objective-c class whose variables are not visible to my photo class.

The subroutine below is from the photo class. It is called after the user has chosen an image from the iphone photo gallery:

- (void)imagePickerController:(UIImagePickerController*)picker 
    didFinishPickingImage:(UIImage*)image 
              editingInfo:(NSDictionary*)editingInfo
{ 
    // I do something with the image here
    [self uploadImage];
    // now I dismiss the modalviewcontroller for the photo library
    [self dismissModalViewControllerAnimated:YES]; 
    // creating and displaying the view that will allow a user to enter a comment
    UserPhotoComment* comment = [[UserPhotoComment alloc] init];
    [self presentModalViewController:comment animated:YES];
    // how do I get the value entered by user? The text is in another obj-c class.
    // dismissing the modal view for the comments
    [self dismissModalViewControllerAnimated:YES]; 
    [picker release]; 
}
  • 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-12T12:32:40+00:00Added an answer on May 12, 2026 at 12:32 pm

    This is a typical example of where you should implement your own delegate. Example:

    @protocol UserPhotoCommentDelegate;
    
    @interface UserPhotoComment : UIViewController {
      id<UserPhotoCommentDelegate> delegate;
      // ... more instance variables.
    }
    @property(nonatomic,assign) id<UserPhotoCommentDelegate> delegate;
    // More interface definitions...
    @end
    
    @protocol UserPhotoCommentDelegate
    -(void)userPhotoComment:(UserPhotoComment*)userPhotoComment
              didAddComment:(NSString*)comment;
    @end
    

    Now just rewrite your previous code as this:

    - (void)imagePickerController:(UIImagePickerController*)picker 
            didFinishPickingImage:(UIImage*)image 
                      editingInfo:(NSDictionary*)editingInfo
    { 
      // I do something with the image here
      [self uploadImage];
      // now I dismiss the modalviewcontroller for the photo library
      [self dismissModalViewControllerAnimated:YES]; 
      // creating and displaying the view that will allow a user to enter a comment
      UserPhotoComment* comment = [[UserPhotoComment alloc] init];
      comment.delegate = self;
      [self presentModalViewController:comment animated:YES];
      [comment release]; // Owned by self now!
      //[picker release]; // If properly releases as comment is, this is not needed here.
    }
    
    -(void)userPhotoComment:(UserPhotoComment*)userPhotoComment
              didAddComment:(NSString*)comment
    {
      // Do what you need with the comment in comment.
      [self dismissModalViewControllerAnimated:YES];
    }
    

    And in UserPhotoCommen you send the result back to the delegate when proper, perhaps when some text editing ends like this:

    - (void)textFieldDidEndEditing:(UITextField *)textField
    {
      [self.delegate userPhotoComment:self didAddComment:textField.text];
    }
    

    As seen in just these short examples both UIImagePickerController and UITextField all uses delegates to return result. This is the Cocoa way, and how Apple would do it, so you should too.

    I would also rename UserPhotoComment into something like UerPhotoCommentController, because the name UserPhotoComment implies it is a model object containing a comment, not a UIViewController subclass used to retrieve the comment.

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

Sidebar

Related Questions

I am attempting to allow user to upload videos to Flickr from an Asp.net
I am attempting to create a web page that will allow a user to
I've got a number of drop down lists, which allow the user to select
I am attempting to write a custom control. I want to allow its user
I am attempting to collect data from a user in the form of an
I'm attempting to implement a feature where a user can select some text in
I am attempting to allow a user to type in their search query in
I am having a bit of trouble attaching images from the Photo Gallery to
I've got a TextView that I would like to allow the user to select
I am attempting to make a simple PhoneGap app that will allow a user

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.