Reputation: 5462
I want to add a tabbar to a uiviewcontroller like this image:
The top part (2labels and UIScrollView ) are fix and just the bottom part change when user changed tab bar items. I added the tab bar controller from object in xcode to my uiviewcontroller but i have no idea how we can create views of tab bar controller how just change part of page.
EDIT: I use this code for this:
UIViewController viewController1, viewController2;
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) {
viewController1 = new FirstViewController ("FirstViewController_iPhone", null);
viewController2 = new SecondViewController ("SecondViewController_iPhone", null);
} else {
viewController1 = new FirstViewController ("FirstViewController_iPad", null);
viewController2 = new SecondViewController ("SecondViewController_iPad", null);
}
UITabBarController tabBarController= new UITabBarController ();
tabBarController.ViewControllers = new UIViewController [] {
viewController1,
viewController2,
};
UIView v= tabBarController .View ;
v.Frame = new Rectangle (0,150,320,260);
UITabBar tb= tabBarController .TabBar;
tb.Frame = new RectangleF (0,410,320,50);
this.View .AddSubview (v );
this .View .AddSubview (tb);
but it is not working. The tab bar view fill all the view and when i click on buttons of uitabbar i get exception and app force close.
Upvotes: 1
Views: 681
Reputation: 2171
You might not need the tabbar to reproduce this behavior.
In your "place should change...", just set a plain UIView and we are going to call it container.
In your view controller's viewDidLoad, create your three views and keep them in memory let's call them detailView, mapView, agentView.
Then, at the bottom, you can just add 3 UIButton. On each button press action (TouchUpInside) you add the related view as container subview (i.e agentButton.TouchUpInside += () => container.AddSubView(detailsView); * do not forget to remove the previous one.
EDIT :
this.View .AddSubview (tabBarController.View);
tabBarController.View.Frame = new RectangleF(....);
I've tried this in a sample project and it works
Upvotes: 1