我是 iOS 开发的新手,我想将 NSMutableArray 从一个视图控制器传递到另一个视图控制器,但总是给我空值
第一视图控制器.h
@interface FirstViewController : UIViewController
@property (nonatomic, retain) NSMutableArray *colorArray;
-(IBAction)btn:(id)sender;
第一视图控制器.m
@implementation FirstViewController
-(IBAction)btn:(id)sender
{
SecondViewController* secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondViewController.animalArray = self.colorArray;
NSLog(@"%@",secondViewController.animalArray); // here its not null
[self.navigationController pushViewController:secondViewController animated:YES];
}
SecondViewController.h
@interface SecondViewController : UIViewController
@property (nonatomic, retain) NSMutableArray *animalArray;
第二视图控制器.m
我只使用了 NSLog(@"animalArray:%@",self.animalArray); 在 viewDidLoad 中检查值但给我 null
有什么我想念的吗?
编辑 :
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"indidLoad%@",self.animalArray);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"inwillAppear%@",self.animalArray);
}