(我使用C#/ Xamarin,但怀疑的问题是具体到这一点。)iOS视图控制器未被发布?
当我添加一个视图控制器,然后将其删除 - 这是DidReceiveMemoryWarning仍然被称为(在模拟器和真实设备) ,所以它不能被释放。我已经收窄,这: -
UIViewController vc=(UIViewController)this.Storyboard.InstantiateViewController(identifier);
this.AddChildViewController(vc);
vc.RemoveFromParentViewController();
vc=null;
,并呼吁DidMoveToParentViewController和WillMoveToParentViewController(如文档中所述)并没有帮助:
UIViewController vc=(UIViewController)this.Storyboard.InstantiateViewController(identifier);
this.AddChildViewController(vc);
vc.DidMoveToParentViewController(this);
vc.WillMoveToParentViewController(null);
vc.RemoveFromParentViewController();
vc=null;
然后模拟内存警告和VC DidReceiveMemoryWarning即使没有提及它也会被调用。当它作为子控制器被删除并且没有对其进行引用时,这是如何实现的。当我使用在故事板中设置的segue转到UINavigationController中的详细视图时,例如,在回到根控制器后,细节控制器仍然收到DidReceiveMemoryWarning消息时,也发生了同样的情况。
任何帮助了解这将不胜感激
UPDATE: 现在我的问题是嵌入在一个UINavigationController
我添加了导航控制研究一个简单的UIViewController ER:
this.nc=(UINavigationController)this.Storyboard.InstantiateViewController("NavigationController");
this.AddChildViewController(this.nc);
this.nc.DidMoveToParentViewController(this);
和以后删除(它的加载后):
this.nc.WillMoveToParentViewController(null);
this.nc.RemoveFromParentViewController();
this.nc=null;
而这一切工作正常(它不保留)。但是如果我在ViewController的ViewDidLoad方法中添加这个简单的行,那么ViewController IS就会被保留!
Console.WriteLine("this.NavigationController={0}",this.NavigationController);
即,只是访问“this.NavigationController”导致VC被保留!
所以每次我运行它,我得到另一个ViewController保留!
任何想法?
这将有助于添加c#标记,因为它与Obj-C语法不同(即Obj-C中的“this。”是“self”)。 – CaptJak