I have two view controllers: BSViewController
which contains the source ivars number
and array
, and BSotherViewController
which as the target needs to receive the ivars . (BSViewController
has a button on it that is segues to BSotherViewController
.)
How can I access the value of the two ivars in BSotherViewController
?
BSViewController.h
#import <UIKit/UIKit.h>
@interface BSViewController : UIViewController
@property (nonatomic) NSInteger number;
@property (nonatomic, weak) NSArray * array;
@end
BSViewController.m
#import "BSViewController.h"
@interface BSViewController ()
@end
@implementation BSViewController
@synthesize number;
@synthesize array;
- (void)viewDidLoad
{
[super viewDidLoad];
BSViewController *view = [[BSViewController alloc] init];
NSArray* _array = [NSArray arrayWithObjects: @"manny",@"moe",nil];
view.array = _array;
view.number = 25;
}
@end
BSotherViewController.h
#import <UIKit/UIKit.h>
@class BSViewController;
@interface BSotherViewController : UIViewController
@end
BSotherViewController.m
The problem below is that aview.number
is 0, not 25; and aview.array
is null.
#import "BSotherViewController.h"
#include "BSViewController.h"
@interface BSotherViewController ()
@end
@implementation BSotherViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
BSViewController *aview = [[BSViewController alloc] init];
NSLog(@"other view: %@", aview);
NSLog(@"other number: %d", aview.number); // produces 0, not desired 25
NSLog(@"other array: %@", aview.array); // produces null, not desired manny,moe
}
@end