xamarin.ios - switching between uiviewcontrollers without a UI navigator control -
i want switch between 2 uiviewcontroller classes programmatically without ui control uitabbarcontroller adds ui application.
my main loads first view controller addsubview.
vc1 = new viewc1(); window.addsubview(vc1.view); window.makekeyandvisible ();
i can load second viewcontroller first 1 presentmodalviewcontroller
vc2 = new viewc2(); presentmodalviewcontroller(vc2, true);
but need switch , forth, , release old viewcontrollers save memory. best way this? dismissmodalviewcontrolleranimated(false); in 2nd view controller isnt releasing memory , dont want modal "windows" doesnt seem optimal. have custom ui tabbar controller not wanted.
you can in simple code. can't release view controllers required handle user interactions such button tap events etc. adding view window preserve view instance. if release view controller instance, bad access error or unrecognized selector error.
so let main code be
if(vc1==nil) vc1 = new viewc1(); window.addsubview(vc1.view); window.makekeyandvisible ();
and switch code 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 helps... followed syntax
Comments
Post a Comment