Wednesday, January 13, 2010

UITabBarController (kind of) inside a Modal child view

I've been playing quite a bit with MonoTouch - love it

It won't be a long term solution I feel (I *think* Silverlight is coming to the iPhone soon!) but it is a good solution for me right now.

One of the problems I've had is trying to get a UITabBarController to work in a child View - basically I just can't work out how to do this in Interface Builder.

To work around it I tried this code instead - using a UITabBar and custom linking code rather than using the "full" UITabBarController.

public override void ViewDidLoad ()
{
base.ViewDidLoad ();
childOne.Text = "one";
childTwo.Text = "two";
mainView.AddSubview(childOne.View);
mainView.AddSubview(childTwo.View);
mainView.BringSubviewToFront(childOne.View);
tabbar.SelectedItem = tabitemOne;
tabbar.Delegate = new MyUITabBarDelegate(this);
}


class MyUITabBarDelegate : UITabBarDelegate
{
TabViewController tvc;
public MyUITabBarDelegate (TabViewController _tvc)
{
tvc = _tvc;
}
public override void ItemSelected (UITabBar tabbar, UITabBarItem item)
{
if (item.Tag == 0)
{
tvc.mainView.BringSubviewToFront(tvc.childOne.View);
//while (tvc.mainView.Subviews.Count() > 0)
// tvc.mainView.Subviews[0].RemoveFromSuperview();
//tvc.mainView.AddSubview(tvc.childOne.View);
}
else
{
tvc.mainView.BringSubviewToFront(tvc.childTwo.View);
//while (tvc.mainView.Subviews.Count() > 0)
// tvc.mainView.Subviews[0].RemoveFromSuperview();
//tvc.mainView.AddSubview(tvc.childTwo.View);
}
}
}



No comments:

Post a Comment