在我的代码中,我为我的子类中的主类声明了一个@property
,以便在那里设置值
@property(nonatomic,retain) MainViewController *father;
但我注意到 retain
使 dealloc
方法没有在我的主类中调用,但是当我将它更改为:
@property(strong, nonatomic) BabyViewController *father;
dealloc
方法返回被调用。
我这样做时并不知道这是否会影响我的代码性能。
我在我的主类中使用了这个属性
来做到这一点:
subClass* controller = [[subClass alloc] initWithPageNumber:page];
controller.father=self;
[controller.view removeFromSuperview];
这是我能做的最好的了吗??
最佳答案
更好的是,您可以使用 assign
属性来声明 viewControllers
和 delegates
。它将分配数据而不会 dealloc
变量。所以像这样使用,
@property(nonatomic,assign) MainViewController *father;
关于iphone - Objective-C @property 类对象的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16295288/