Objective c 在其他班级接受ivar

Objective c 在其他班级接受ivar,objective-c,ivar,Objective C,Ivar,我有两个视图控制器:BSViewController,其中包含源IVAR编号和数组,以及作为目标需要接收IVAR的BSotherViewController。(BSViewController上有一个按钮,可连接到BSotherViewController) 如何访问BSotherViewController中两个IVAR的值 BSViewController.h #import <UIKit/UIKit.h> @interface BSViewController : UIVie

我有两个视图控制器:
BSViewController
,其中包含源IVAR
编号和
数组
,以及作为目标需要接收IVAR的
BSotherViewController
。(
BSViewController
上有一个按钮,可连接到
BSotherViewController

如何访问
BSotherViewController
中两个IVAR的值

BSViewController.h

#import <UIKit/UIKit.h>

@interface BSViewController : UIViewController
@property (nonatomic) NSInteger number;
@property (nonatomic, weak) NSArray * array;
@end
#import <UIKit/UIKit.h>

@class BSViewController;
@interface BSotherViewController : UIViewController
@end
b其他视图控制器

#import <UIKit/UIKit.h>

@interface BSViewController : UIViewController
@property (nonatomic) NSInteger number;
@property (nonatomic, weak) NSArray * array;
@end
#import <UIKit/UIKit.h>

@class BSViewController;
@interface BSotherViewController : UIViewController
@end

当您从
BSOtherViewController
实例化
BSViewController
时,您正在调用init方法。值在
BSViewController
中的
viewDidLoad
中设置,并且在实际加载视图之前不会调用该方法

尝试重写init方法并设置值

- (id)init {

if (self = [super init]) {
    //Set values
     NSArray*  _array = [NSArray arrayWithObjects: @"manny",@"moe",nil];
     self.array = _array;
     self.number = 25;
}
return self;
}

将BSViewControllerviewDidLoad方法替换为init,如下所示:

- (id)init {

if (self = [super init]) {

    NSArray*  _array = [NSArray arrayWithObjects: @"manny",@"moe",nil];
    self.array = _array;
    view.number = 25;

}
return self;
}

我怎么修理它?如果我把
@property(强,非原子)放在BSViewController*视图中
into.h我得到了不兼容的属性类型。将init方法添加到BSViewController,并在该方法中设置值,这不是在欺骗吗,因为在知道number和array的值之前执行
init
。我试图创建另一个
-(id)initWithNumber:(NSInteger)number数组:(NSArray*)数组{self=[super init];if(self){unumber=number;{uarray=array;return self;}return nil;}
并在计算
number
array
后调用它,但我得到0和空结果。你也能对这些想法做出反应吗?为什么你对数组的引用较弱?尝试将(非原子的,赋值的)添加到nsintegerpeople中,我拒绝接受这个答案,因为我发现其他东西妨碍了它的工作。[例如](继续提问。最近,我发现所涉及的segue是推式还是模态segue是有区别的。当我在UINavigationController中嵌入所涉及的VCs时,只有推式segue起作用,模态不起作用。我不知道为什么,但这可能是我的方法和问题中未发现的问题。谢谢r所有人的帮助。回答很好。看起来很像我的:)我认为view.array应该被self.array.oops替换…从零字代码粘贴的副本…没有注意到…现在更正…tnx:)@Johan:init将是这样的,无论谁回答这个问题。。。。所以它看起来可能很相似……)请看我对另一个答案的评论(关于作弊?)。