2つのViewControllerがあります。1つBSViewController
はソースのivarnumber
とarray
を 含み、もう1つBSotherViewController
はターゲットとしてivarを受け取る必要があります。(BSViewController
セグエのボタンがありますBSotherViewController
。)
の2つのivarの値にアクセスするにはどうすればよい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
、25ではなく0であるということです。そしてaview.array
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