情況:有推送UIViewController的UINavigationController。爲什麼在UINavigationController和UIViewControllers之間沒有保留循環
1.UIViewController具有的UINavigationController
強參考@property(nonatomic,readonly,retain) UINavigationController *navigationController
2.UINavigationController存儲的NSArray
@property(nonatomic,copy) NSArray *viewControllers;
UINavigationController的視圖控制器應該有強引用本NSArray的(或將被重新分配)。
3.NSArray對包含的視圖控制器有很強的參考。
UPDATE: 讓我們在代碼某處想象,我們有以下:
UIViewController *A = [ [UIViewController alloc] init ];
UINavigationController *B = [ [ UINavigationController alloc ] initWithRootViewController:A ];
// Here we have strong reference in A to B, in B to B.viewControllers (count == 1) and in B.viewControllers to A.
// Local variable's strong references to A and B
A = nil; B = nil;
// Local variable's strong references has gone
// But we should still have retain loop here
// Magic !?? :)
我的問題是,爲什麼我們沒有在這裏保留循環?
只有當處於堆棧中的viewControllers時,您的觀點3纔是真實的。當ViewController被移除(解散)時,它不再是真的。 –
請參閱我的示例(下面的更新)哪裏查看控制器彈出? – Avt
這裏有一個循環,但是因爲它可以被破壞,所以這不是問題。並非所有的參考循環都是問題。你的代碼片段不會改變文森特的答案。 –