0

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...

jharr100
  • 1,449
  • 24
  • 51
  • Your scenario is not very clear. Usually a TabBar is the root controller, and each tab is assigned a view controller or navigation controller. The tab bar control handles switching views for you, you should not have to do anything. – Jason Jul 19 '13 at 18:33
  • idk whether there is a difference between using a tabbar vs a tabbarcontroller but my tab bar resides within my mainviewcontroller...not as a root of its own... – jharr100 Jul 19 '13 at 18:37
  • So you have a UIView in the ViewController you want to show when a tabbar element is pressed? – Arbitur Jul 19 '13 at 18:41
  • yes...I updated the question with an image - hopefully the image will help clarify – jharr100 Jul 19 '13 at 18:50
  • Maybe this: LocationNotesViewController lnvc = [[LocationNotesViewController alloc] init]; – Arbitur Jul 19 '13 at 19:01
  • is this just instantiating the view controller? – jharr100 Jul 19 '13 at 19:05

3 Answers3

1

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.

CaptJak
  • 3,592
  • 1
  • 29
  • 50
0

To switch UIViewControllers use this piece of code:

UIViewController *viewController = 
                 [self.storyboard instantiateViewControllerWithIdentifier:@"4"];
                 [self presentViewController:a animated:YES completion:nil];
Arbitur
  • 38,684
  • 22
  • 91
  • 128
  • i dont want to switch view controllers...i want to switch views...i dont know whether i am able to do that - the second view is a blank view that and when i tap a button i want to load another view in its place... – jharr100 Jul 19 '13 at 18:34
  • @jharr100 Then the second view will not be able to do anything. It needs to be another VC. Are you just trying to keep your tabBar on every view? What do you want to accomplish with only changing the view and not VC? – CaptJak Jul 19 '13 at 18:38
  • @jharr100 Wow, neato. Honestly not sure on tabBar, but if you add button (to, say a toolbar) the you can have the button programatically change out the view. Sorry for polluting your post Arbitur – CaptJak Jul 19 '13 at 19:00
  • That sounds like an option how would i do it in that instance...these tabbar buttons have some event equivalent to touchupinside that a button would have so it would be similar - i think? – jharr100 Jul 19 '13 at 19:04
  • I found a way to get events from the tabbar on this link http://stackoverflow.com/questions/2801299/how-can-i-get-tabbar-item-buttons-click-event-by-clicking-on-tabbaritem-button – Arbitur Jul 19 '13 at 19:17
  • @Arbitur yea I have that part working already its just the switching views part thats throwing me off... – jharr100 Jul 19 '13 at 19:21
  • Is MainPageTabBarView the Viewcontroller in the picture and the white bix under the mapview a UIView which is suppose to run the Viewcontroller LocationNotesViewController? in that case use a container view. – Arbitur Jul 19 '13 at 19:25
  • I will look up containerview but I think that has multiple view controllers...I only want to use multipleviews...even though LocationNotesViewController is a view controller I only need the view - thats whys like `lnvc.View` - but i will look into this – jharr100 Jul 19 '13 at 19:35
0

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);
jharr100
  • 1,449
  • 24
  • 51