switching between uiviewcontrollers without a UI navigator control

强颜欢笑 提交于 2019-12-03 20:52:55

You can do it in simple code. But you can't release the view controllers as it required to handle user interactions such as button tap events etc. Adding a view to window will only preserve view instance. If you release your view controller instance, you could get a bad access error or unrecognized selector error.

So let your main code be

if(vc1==nil)
  vc1 = new viewC1();
window.addSubView(vc1.view);
window.MakeKeyAndVisible ();

And your switch code will be

if(vc2==nil)
   vc2 = new viewC2();
if(vc1.view.superview!=nil){
   vc1.view.removefromSuperView();
   window.addsubview(vc2.view);
} else {
   vc2.view.removeFromSuperView();
   window.addsubview(vc1.view);
}

Now in dealloc method add

vc1.release();
vc2.release();

Thats it...Hope this helps... I just followed your syntax

You can use a UINavigationController still, you don't need the extra UI that it provides. You can use the .Hidden property of the UINavigationBar to hide that. To switch between views you can just use PushViewController(controller, animated) to push the new view. If you want to release the old controller then you can just set the UINavigationController's .ViewControllers property using:

navigationController.ViewControllers = new UIViewController[1]{ vc2 };

this will remove the reference of the first controller and make the second controller the root. (this will also work the other way around!)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!