iphone - Objective-C @property 类对象的变量

标签 iphone ios objective-c xcode subclass

在我的代码中,我为我的子类中的主类声明了一个@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 属性来声明 viewControllersdelegates。它将分配数据而不会 dealloc 变量。所以像这样使用,

@property(nonatomic,assign)  MainViewController *father;

关于iphone - Objective-C @property 类对象的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16295288/

相关文章:

ios - UITableViewCell 仅在滚动时加载内容

iphone - objective-c : Write a function to return the position of the last character in a UILabel?

iphone - 如何在UITableViewCellStyleSubtitle的cell.detailText.label中添加两个标签?

ios - 模拟 API 测试的 URLSession 是将无法识别的选择器发送到实例

ios - ImageView 上的平滑线条

objective-c - iOS 应用之间同步数据有什么好的解决方案?

objective-c - 如何访问文档文件夹

objective-c - 显示 NSDictionary 中的每个项目

ios - UIButtonTypeInfoDark Touch Area

ios - 如何从框架包中加载场景文件 .scn