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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:45:53+00:00 2026-06-16T04:45:53+00:00

I have a prepareforsegue method that takes a picture and shows it on a

  • 0

I have a prepareforsegue method that takes a picture and shows it on a different viewcontroller. So I need to set a label on the secondviewcontroller at the same time that the pictures is showing, later I’ll do a random word generator on that label but right now I just need to set the label. I tried putting it inside the prepareforsegue method but it gives me an error. Here’s all my code:

//ViewController.m   

     -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
        if([segue.identifier  isEqualToString:@"CameraSegue"] || [segue.identifier isEqualToString:@"LibrarySegue"])
        {

            UIImagePickerController *controller = [segue destinationViewController];
            controller.sourceType = [segue.identifier isEqualToString:@"LibrarySegue"] ?  UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypeCamera;
            controller.delegate = self;


        }
        else if([segue.identifier isEqualToString:@"ShowImageViewController"]){

            UIImage *image = (UIImage*)sender;
            ShowImageViewController *viewController = segue.destinationViewController;
            viewController.pickedImage = image;

            UILabel *label = (UILabel *) sender;
            ShowImageViewController *vc = segue.destinationViewController;
            vc.cap = label;
           //I tried to set the label here
            label.text = @"Hello";

        }
    }

    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [self dismissViewControllerAnimated:YES completion:^{
            picker.delegate = nil;
            [self performSegueWithIdentifier:@"ShowImageViewController" sender:image];
        }];
    }

//SeconViewController.h
@property(nonatomic, strong) UIImage *pickedImage;
@property (weak, nonatomic) IBOutlet UIImageView *pickedImageView;
@property(nonatomic, retain) IBOutlet UILabel *cap;

//SecondViewController.m

-(void)viewWillAppear:(BOOL)animated{
    self.pickedImageView.image = self.pickedImage;
}
  • 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-16T04:45:54+00:00Added an answer on June 16, 2026 at 4:45 am

    You’re casting the sender to two very different things.

    UIImage *image = (UIImage*)sender;
    ShowImageViewController *viewController = segue.destinationViewController;
    viewController.pickedImage = image;
    
    UILabel *label = (UILabel *) sender;
    ShowImageViewController *vc = segue.destinationViewController;
    vc.cap = label;
    label.text = @"Hello";
    

    You cannot cast a UIImage to a UILabel and expect things to go smoothly. In prepareForSegue, you send along an image, not a label.

    Can you just change the bottom four lines to:

    viewController.cap.text = @"Hello";
    

    In this case, another option would be to define a new property in ShowImageViewController as you did for the image.

    //SecondViewController.h
    @property(nonatomic, strong) UIImage *pickedImage;
    @property (weak, nonatomic) IBOutlet UIImageView *pickedImageView;
    @property(nonatomic, retain) IBOutlet UILabel *cap;
    @property (nonatomic, strong) NSString pickedLabel; //New property
    
    -(void)viewWillAppear:(BOOL)animated{
        self.pickedImageView.image = self.pickedImage;
        self.cap.text = self.pickedLabel;
    }
    

    And then in prepareForSegue

    UIImage *image = (UIImage*)sender;
    ShowImageViewController *viewController = segue.destinationViewController;
    viewController.pickedImage = image;
    viewController.pickedLabel = @"Hello";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 6 segues that perform the same action in the prepareForSegue method,
I have this code in a prepareForSegue method // Get destination view UIViewController *viewController
I'm setting a property for a viewcontroller which I set on a prepareForSegue method.
I have a modal view controller that attempts to set an flag (an NSNumber
I have a UItableView that segues to a different view controller. I'm using a
I'm trying to set an Integer on another VC using prepareForSegue method. I've got
I'm having trouble sending data to a different view using the prepareForSegue method… I
I have an app that has two viewcontrollers Viewcontroller and OptionsViewController. Viewcontroller is the
I have a view that through a prepareSeque method should pass whatever is written
have written this little class, which generates a UUID every time an object of

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.