Search code examples
iosios5uinavigationcontrollerxcode4.2pushviewcontroller

ios5 passing data from calloutAccessoryControlTapped to another controller


I am trying to send a nsmutablearray from one navigational embedded view controller to another viewcontroller after this method

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{NSLog(@"tapped %@ %d",view.annotation.title,[res count]);
    gpDetailViewController *gpDetailView = [[gpDetailViewController alloc] init];
    gpDetailView.title = @"Details";
    gpDetailView.detailArray = res;
         [self.navigationController pushViewController:gpDetailView animated:YES];



} 

is executed. Here is the interface and implementation files for gpDetailViewController.

//
//  gpDetailViewController.h
//  livewell prototype
//
//  Created by MyOxygen Mobile on 02/05/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface gpDetailViewController : UIViewController{
    NSMutableArray *detailArray;
}
@property (nonatomic,retain) NSMutableArray *detailArray;


@end

and gpDetailViewController.m

//
//  gpDetailViewController.m
//  livewell prototype
//
//  Created by MyOxygen Mobile on 02/05/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "gpDetailViewController.h"

@interface gpDetailViewController ()

@end

@implementation gpDetailViewController
@synthesize detailArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    detailArray = [[NSMutableArray alloc]init];

    NSLog(@"%@",[self.detailArray count]);
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

I am getting a null value when i am trying to print the array elements size. What could be the reason?


Solution

  • Instead of

    NSLog(@"%@",[self.detailArray count]);
    

    try this

    NSLog(@"%d",[self.detailArray count]);
    

    count is an integer, not a class