When I used tradition function

   [self.navigationController pushViewController:viewcontroller animated:YES];

or

   [self presentModalViewController:viewcontroller animated:YES];,

Everything is ok. But when I used

   [self.view addSubview:viewcontroller.view];

I can't do anything in next view, all view's membory pointer has gone. And it crashes all the time.

有帮助吗?

解决方案

I think your viewController object is declared locally. Make it class level variable (declare in .m file). Reason why your app crashes is you declare object locally and it is released after that function is finished. So no object for addSubView. When you push or present object is retained once and hence not released and application works. So if you want to use addSubView then make it class level variable so that it wont be released.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top