我有两个视图控制器:BSViewController
其中包含源 ivarsnumber
和array
,以及 BSotherViewController
作为目标需要接收 ivars 。(BSViewController
上面有一个按钮,用于连接BSotherViewController
。)
如何访问两个 ivars 中的值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
下面的问题aview.number
是0,不是25;并且aview.array
为空。
#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