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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:34:25+00:00 2026-06-10T07:34:25+00:00

I am trying to pass an object between two ViewControllers in a Storyboard in

  • 0

I am trying to pass an object between two ViewControllers in a Storyboard in objective-C iPhone app. (iOS 5/ XCode 4)

The first ViewController is a map with annotations (each annotation object is called MyLocation, it is displayed on a map by a containing MyLocationView). The user clicks an annotation, a callout appears, then user clicks the right arrow to load an annotation detail view (a new ViewController), which displays more details on the selected annotation.

I have defined a segue ‘SegueAnnotationDetail’ which moves between the main View Controller and the annotation details view controller.

I have defined an instance variable in the main view controller to hold the annotation that the user clicked, and then I am going to pass it to the annotation details view (ViewController.h):

@interface ViewController : UIViewController <MKMapViewDelegate> {
    MKAnnotationView *selectedAnnotation;
}

So in the main view controller (ViewController.m) I have the following:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
    selectedAnnotation = view;

    [self performSegueWithIdentifier:@"SegueAnnotationDetail" sender:self];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"SegueAnnotationDetail"])
    {
        LocationDetailViewController *vc = [segue destinationViewController];

        [vc setLocation:selectedAnnotation];
    }
}

Then in LocationDetailViewController (which is the 2nd view controller displayed the details for each annotation), I have

@interface LocationDetailViewController : UIViewController

@property MKAnnotationView* location;

@end

Each annotation is a MKPinAnnotationView and is created as follows, in the viewForAnnotation method, also inside ViewController.m

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    static NSString *identifier = @"MyLocation";

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    // removed some code related to animation view queue here for simplicity

    annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];

    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    return annotationView;

}

The problem is, when this runs, the app just crashes at the line:

[vc setLocation:selectedAnnotation];

UPDATE

The error message in the console is:

2012-08-26 18:33:10.615 ArrestsPlotter[79918:c07] -[UIViewController setLocation:]: unrecognized selector sent to instance 0x6ea0b60
2012-08-26 18:33:10.615 ArrestsPlotter[79918:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setLocation:]: unrecognized selector sent to instance 0x6ea0b60'
*** First throw call stack:
(0x165e022 0x12cecd6 0x165fcbd 0x15c4ed0 0x15c4cb2 0x3977 0x85c4be 0x4f95ab 0x385b 0x361f8c 0x36d8ba 0x165fe99 0x43414e 0x4340e6 0x4daade 0x4dafa7 0x4da266 0x4593c0 0x4595e6 0x43fdc4 0x433634 0x1da5ef5 0x1632195 0x1596ff2 0x15958da 0x1594d84 0x1594c9b 0x1da47d8 0x1da488a 0x431626 0x231d 0x2285)

terminate called throwing an exception(lldb)

When I comment out the offending line, the app runs ok albeit without showing the right info on the details page.

WTF am I doing wrong?

  • 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-10T07:34:27+00:00Added an answer on June 10, 2026 at 7:34 am

    Ok, I answered it myself. I’ll post the answer here since it’s not that clear on the internet.

    To associate a view controller file with a specified scene in the storyboard, click on the scene, then use the Attribute Inspector, select Custom Class and choose the class to use.

    That is how you link a view controller with a scene. That was what was causing the problem here (see comments to the first answer)

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

Sidebar

Related Questions

I am trying to pass data between two pages using Session State in ASP.NET.
I want to pass on object between two activities in Android which has lead
I'm trying to pass an object between 2 VCs, from a popover to the
I'm trying to pass an object from one controller action to another. The object
I'm trying to pass a JavaScript object to a PHP script through jquery.ajax() ,
I was trying to pass a string object to System.out.printf(...) in Java, but I
I am trying to pass a simple JSON object to a controller using MVC3
I'm trying to pass a dynamic, user created object through AJAX to some C#.
In javascript, I have an object that I am trying to pass but not
The following is the custom class, whose object I am trying to pass: package

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.