ios5将数据从calloutAccessoryControlTapped传递到另一个控制器

时间:2012-05-02 16:39:41

标签: ios ios5 uinavigationcontroller xcode4.2 pushviewcontroller

我试图在此方法之后将nsmutablearray从一个导航嵌入式视图控制器发送到另一个viewcontroller

- (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];



} 

已执行。 这是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

和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

当我尝试打印数组元素大小时,我得到一个空值。 可能是什么原因?

1 个答案:

答案 0 :(得分:1)

而不是

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

试试这个

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

count是一个整数,而不是一个类