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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:13:11+00:00 2026-06-13T18:13:11+00:00

I have a CollectionViewController and a CollectionViewCell. I am fetching data from a database,

  • 0

I have a CollectionViewController and a CollectionViewCell. I am fetching data from a database, so when the controller is loaded it dynamically creates the corresponding cells.

Every cell has a UIButton and UITextView.
I am using the UIButton to display a picture (if it exists in the database) or capture an image (if pressed).

InboundCollectionViewController.m

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{
    InboundCollectionViewCell *inboundDetailCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"InboundDetailCell" forIndexPath:indexPath];

    Image *current = [images objectAtIndex:indexPath.row];

    [inboundDetailCell.imageType setText:[NSString stringWithFormat:@"%@", [current pd_description]]];

    if ([current.pd_image isKindOfClass:[NSData class]] == NO) {
        [inboundDetailCell.imageButton addTarget:self action:@selector(useCamera)     forControlEvents:UIControlEventTouchUpInside];
    }
    else {
        [inboundDetailCell.imageButton setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    }

    return inboundDetailCell;
}

So far, so good. I launch my app. The collection view controller populates itself with cells depending on the results from the database.

If the image field has an image, then “check.png” is loaded in the image property of my custom imageButton.

If the image field does not have an image, then the TouchUpInside action for the imageButton is set to the method ‘useCamera’.

- (void)useCamera 
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    }
    else
    {
        [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }

    [imagePicker setDelegate:self];
    [self presentViewController:imagePicker animated:YES completion:NULL];
}

Now, according to the tutorial I am following, I have to implement the following code:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    // set image property of imageButton equal to the value in UIImage 'image' variable ???

    [self dismissViewControllerAnimated:YES completion:NULL];
}

In most examples I found, the ImageView and the ImagePickerController are created within the same ViewController. Therefore it is easy to access the image property of the ImageView (or the button in my case).

My problem is that my ‘IBOutlet UIButton imageButton’ is located inside InboundCollectionViewCell, not InboundCollectionViewController. So, I cannot find a way to pass the image returned from the camera, to the image property of my button.

Please note that I am very new to both Objective C and Xcode and this is my first project.. so be gentle! 😛 🙂

Thank you in advance!

  • 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-06-13T18:13:12+00:00Added an answer on June 13, 2026 at 6:13 pm

    Make sure that useCamera receives the button that’s been pressed, and store that in a member variable:

    - (void)useCamera:(id)sender {
        UIButton *button = (UIButton *)sender;
        self.lastButtonPressed = sender;  // A member variable
    
        ...
    }
    

    Note that you’ll need to remap the touchUpInside to this function since the signature has changed.

    Now, in imagePickerController:didFinishPickingMediaWithInfo: you can access the member variable self.lastButtonPressed to update its image.

    Tim

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

Sidebar

Related Questions

Have one Doubt In MVC Architecture we can able to pass data from Controller
have written this little class, which generates a UUID every time an object of
have a nice day. I got problem when trying to create an image from
Have two tables say ABC and XYZ and contain one column which data will
Have added activityviewcontroller to the main controller -(void)ActionSheet2:(id)sender { UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the

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.