Sara Shumika Sara Shumika - 2 months ago 8x
Objective-C Question

iOS : pass data from view controller to Detail view controller return null in storyboard

I have json file, I can print all the informations to my

, from this json I show different location in my map, when I click on annotation button I have to show
, I can show my detail
but my data is null, would you please help me in this implementation, Thanks in advance!

Here is my method:

- (void)viewDidLoad
[super viewDidLoad];
[self fetchData];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:BASED_URL]];
[request setHTTPMethod:@"GET"];
[request setValue:@"/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

NSURLResponse *response;
NSData *GETReply = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:nil];

NSString *theReply = [[NSString alloc] initWithBytes:[GETReply bytes] length:[GETReply
length] encoding: NSASCIIStringEncoding];

NSLog(@"Reply: %@", theReply);

CLLocationCoordinate2D location;
NSMutableArray *newAnnotations = [NSMutableArray array];
NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData:GETReply
if (error != nil)
// handle the error

for (NSDictionary *dictionary in array)
// retrieve latitude and longitude from the dictionary entry

location.latitude = [dictionary[@"latitude"] doubleValue];
location.longitude = [dictionary[@"longitude"] doubleValue];

// create the annotation
MyAnnotation *newAnnotation;

newAnnotation = [[MyAnnotation alloc] init];
newAnnotation.title = dictionary[@"applicant"];
newAnnotation.subtitle = dictionary[@"company"];
newAnnotation.status = dictionary[@"status"]; = dictionary[@"company"];
newAnnotation.coordinate = location;

[newAnnotations addObject:newAnnotation];

[self.mapView addAnnotations:newAnnotations];

I Have a method that should pass data to my detail view

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
MyAnnotation *annotation = view.annotation;
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:nil
detail.status.text = annotation.status;
NSLog(@"status is%@",annotation.status );

[self.navigationController pushViewController:detail animated:YES];

In my Log I have: status is Active

but in my detail view Log I have Null

#import "ViewController.h"

@interface DetailViewController : ViewController
@property (weak, nonatomic) IBOutlet UILabel *status;


- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.

self.status.text = _status.text;
NSLog(@"Status is %@",_status );
NSLog(@"Status is %@ ",self.status.text);

My status print is : Status is null
Status is null

Update:Here is my label

@property (strong, nonatomic) IBOutlet UILabel *status;


Create one NSString in your DetailViewController header file:

@property (nonatomic, strong) NSString *passData;

your viewDidLoad in DetailViewController

- (void)viewDidLoad
    [super viewDidLoad];
    self.status.text = _passData;

your mapView method in your viewController

detail.passData = annotation.status;