jharr100
jharr100

Reputation: 1469

how do I display different views in a view controller using a tab bar

I have a view controller that has a map view and a second view under the a tab bar. How do I go about updating the second view when I press buttons on the tab bar?

I tried:

LocationNotesViewController lnvc = new LocationNotesViewController();
lnvc.View.Frame = MainPageTabBarView.Frame;
MainPageTabBarView = lnvc.View;

Nothing happens...the view doesn't update.

enter image description here

I want to update the second view with different things when a user clicks on the tabbar...

Upvotes: 0

Views: 896

Answers (3)

jharr100
jharr100

Reputation: 1469

I think this is a work around - but I was able to make this happen by doing:

LocationNotesViewController lnvc = new LocationNotesViewController();
lnvc.View.Frame = new RectangleF(MainPageTabBarView.Frame.X, MainPageTabBarView.Frame.Y -    MainPageTabBarView.Frame.Y, MainPageTabBarView.Frame.Width, MainPageTabBarView.Frame.Height);
MainPageTabBarView.AddSubview(lnvc.View);

Upvotes: 0

user2535467
user2535467

Reputation:

If you put a UIView underlying whatever data you want displayed in it, you can use the IBAction of the tabBar to programtically cahnge out the contents of the UIView.

Or you could have the IBActions of the tabbar create new UIViews on the fly, containing whatever you want inside.

Code to do this would be like explained here: http://www.programmerscountry.com/creating-uiviewcontrols-programatically/.

Not exactly the same, but you will understand how it works from that answer.

Upvotes: 1

Arbitur
Arbitur

Reputation: 39081

To switch UIViewControllers use this piece of code:

UIViewController *viewController = 
                 [self.storyboard instantiateViewControllerWithIdentifier:@"4"];
                 [self presentViewController:a animated:YES completion:nil];

Upvotes: 0

Related Questions