0

这个问题与这个有关,但更简单。[我想我可能已经接近完成这些愚蠢的问题,可以开始认真做事了:)]。

我有一个retain属性并像这样设置它:

UINavigationController *thing = [[UINavigationController alloc] initWithRootViewController:one];
    // thing's retain count is one
navController = thing;
    // thing's retain count is still one!
[thing release];
    // now retain count is zero, which is wrong

我不明白为什么保留计数为零。navController定义为

@property (nonatomic, retain) UINavigationController *navController;

该属性不应该将保留计数增加一吗?

4

1 回答 1

7

问题是:您直接分配给属性的底层实例变量,而不是调用 setter。属性魔法不会以这种方式触发。尝试

self.navController = thing;

相反(其余代码无需更改)。

于 2010-06-20T23:29:46.657 回答