I have a UISegmented control, which act as a tabs. When a tab is clicked I wanted to change the view to another page.
Essentially at the moment I have two views each have their own segment control which switches from one view to the other and vice versa.
If I use PresentModalViewController I continually adding the view to the stack each time the user changes the uiSegment which isn't good.
I want to set the current view to a new view. but at the same time e开发者_运维问答nsure that if I call dismiss I can do back a view My applicantion is structure like so:
[Main Window] --> [VC shows table of items] -->
|--> [VC with Segment control View 1]
| (swap between)
|--> [VC with Segment control View 2]
so in both the views I would have for instance:
View1:
partial void Tabs_Changed (UISegmentedControl sender)
{
if( btnTabs.SelectedSegment == 1) {
View2 view2 = new View2(); //load view 2
this.PresentModalViewController(view2,false);
}
}
View 2:
partial void Tabs_Changed (UISegmentedControl sender)
{
if( btnTabs.SelectedSegment == 0) {
View1 view1 = new View1(); //load view 1
this.PresentModalViewController(view1,false);
}
}
But this is making the app unpredictable presumably cause I'm constantly stacking up views?
Please help.
Jason
Using the PresentModalViewController() method really is not the way to go. You are indeed stacking multiple views which is a bad thing to do.
What I would do is have one view, with the UISegmentedControl and another 2 subviews added to it (use the AddSubview(View) method to do that).
On your viewDidLoad method, create the veiws and hide the second one using:
view1 = new UIView(){BackgroundColor = UIColor.Green};
view2 = new UIView(){Hidden = true, BackgroundColor = UIColor.Red};
this.AddSubview(view1);
this.AddSubview(view2);
Now, in your method:
partial void Tabs_Changed (UISegmentedControl sender)
{
bool v1Visible = btnTabs.SelectedSegment == 0);
view1.Hidden = !v1Visible;
view2.Hidden = v1Visible;
}
I havent run the code, but it should work. Hope this helps.
This might help. switching between uiviewcontrollers without a UI navigator control
but doesnt need an UI to switch, call the App deletegate from your viewcontroller with something like
var appDelegate = (AppDelegate) UIApplication.SharedApplication.Delegate;
appDelegate.switch();
精彩评论