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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:34:10+00:00 2026-06-02T19:34:10+00:00

BACKGROUND: I have a custom UIViewController class where I populate a MKMapView with custom

  • 0

BACKGROUND:

I have a custom UIViewController class where I populate a MKMapView with custom annotations. When the user selects the annotation, details about that annotation are displayed, and a button is also present for the user to select and bring up another UIViewController with details about that point on the map.

The Code:

I initialize the new view controller by creating the class with a UserID (Note: - (id) initWithUserID:(NSInteger) userID; is declared in the header file of the SecondViewController:

@interface SecondViewController ()

@property (nonatomic) NSInteger userID;

@end



@implementation RainFallDetailedViewController

@synthesize userID = _userID;


- (id) initWithUserID:(NSInteger) userID{

_userID = userID;
NSLOG(@"UserID: %i",self.userID); //correctly displays user id

return self;
}

- (void) viewWillAppear{
NSLOG(@"UserID: %i",self.userID); //userid is now 0

Creating the view controller is done when the button is pressed, and then immediately performs the segue to the second view controller:

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

if ([(UIButton*)control buttonType] == UIButtonTypeInfoLight){ //I'm looking for recognition of the correct button being pressed here.
    //SecondViewController is the second view controller with the detailed information about the map point.  
    //DataPoint is a custom class that contains the details regarding the map point.
    SecondViewController *detailedMapController = [[SecondViewController alloc] initWithUserID:((DataPoint *)view.annotation).userID]; 

    NSLOG(@"UserID: %i", ((DataPoint *)view.annotation).userID); //correctly displays userID

    [self performSegueWithIdentifier:@"PinDetail" sender:detailedMapController];


} 
}

PROBLEM:

Using NSLOG I’m able to confirm that the value is being passed correctly when creating the class. However, when I go to use the property userID later on in the code (viewWillAppear), it’s not longer there for me to use. I’m assuming that there’s a memory issue that I’m not taking care of but I can’t seem to figure it out. How do I ensure that the values/object I pass into a class upon creation stay there?

Side Note: I originally tried, passing a PinData object, but ran into the same issue, so I know it’s not a NSInteger problem. I’ve also followed noa’s suggestion and used prepareForSegue however, I get the same problem presented above

  • 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-02T19:34:11+00:00Added an answer on June 2, 2026 at 7:34 pm

    The segue is responsible for instantiating the controller. Don’t instantiate another one – it’ll just be discarded, which is why the property values don’t seem to stick.

    To set up the view controller, override -prepareForSegue: instead, in the parent view controller:

    - (void) prepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender {
        if ([segue.identifier isEqualToString:@"PinDetail"]) {
            SecondViewController *vc = segue.destinationViewController;
            vc.userID = self.userID;
        }
    }
    

    Replace the last block of code above with this:

    self.userID = ((RainFallDataPoint *)view.annotation).userID;
    [self performSegueWithIdentifier:@"PinDetail" sender:self];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a custom collection that is binded to the datagridview this.datagridview.DataSource =
I have a custom UINavigationController that draws a custom background. That navigation controller is
I have a custom tableview cell created programmatically that consists of: a background view
Background info: I have a windows application (in c#) that handles a custom file
I have a JPanel that implements custom drawing to draw a background. Over this,
Background: I have a custom user control based around a WPF TreeView. I've been
I have a custom ViewGroup (blue background) that when touched sometime during the app's
Background I have a custom authentication back end for our django applications that refers
I have inherited my custom class in my project.i.e instead of using the UIViewController
Background I have a custom control that inherits from a TreeView and is modified

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.