0

在我的第一堂课(Secen1ViewController.h)中,我有财产:

@property (nonatomic) BOOL myBoolean;

在我的第二堂课(Secen2ViewController.m)中,我导入了 Secen1ViewController.h 并声明了属性:

@property (strong) Secen1ViewController *parent;

我还在 ViewDidLoad 中初始化了属性:

 _parent = [[Secen1ViewController alloc] init];

然后当按下按钮时我设置属性:

 self.parent.myBoolean=YES;

没有显示错误,但 Scene1 中的 myBoolean 未设置为 yes。

4

3 回答 3

0

尝试替换此代码:

_parent = [[Secen1ViewController alloc] init];    

使用此代码:

self.parent = [[Secen1ViewController alloc] init];    

并确保您综合了所有属性。

于 2013-02-25T19:35:54.177 回答
0

首先添加@class Secen1ViewController (.h)#import Secen1ViewController in (.m)

将您的 myBoolean 属性设置为

@property (assign,nonatomic) BOOL myBoolean;

@synthesize it in (.m)在你身上使用它Secen1ViewController

self.parent = [[Secen1ViewController alloc] init];
self.parent.myBoolean = YES;
于 2013-02-25T17:41:20.123 回答
0

你合成你的布尔变量了吗?显然你可能没有申报

@synthesize myBoolean = _myBoolean;

在你的实现文件中。

于 2013-02-25T18:53:39.697 回答