سؤال

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