0

I've been looking everywhere but can't seem to find any examples/tutorials for my situation (not sure how to google it..) So i have a window where a portion of it should be static (buttons and such) and there is a dynamic part (bottom leftish) that should change subviews.
So what i'm looking for is a way so that clicking the buttons in the static area will change the dynamic area to a view of my choice. I have no idea how to do this using the IB, but doing it programatically seems the only way. Any suggestions(I do not want to use a tab bar controller)?
grey is static area Oh, and is there a benefit to making views and such programatically vs through the IB?

Thanks!

Andrew Park
  • 1,489
  • 1
  • 17
  • 26
  • Change the dynamic area to a view of my choice - Can u explaing more on that ? Do u have other viewcontrollers or do u want to display imageView there ? – stack2012 Jul 20 '11 at 04:54
  • If t is going to be another view, u can create an instance of the other viewcontroller and then u can add it as a subview to the current view whenever the button is clicked. – stack2012 Jul 20 '11 at 04:55
  • when you accomplish this task properly you would be knowing the benefit of making views and such programmatically vs through the IB ... – Maulik Jul 20 '11 at 05:00
  • @iphoneFreak, so i would need a viewcontroller for every subview? i think i read somewhere about apple saying not to do that, but whatever works. But would doing that override the static area? i added the picture for clarification – Andrew Park Jul 20 '11 at 05:13
  • Then instead of viewcontrollers u can create as many UIView as u want and then try the same as I told b4. – stack2012 Jul 20 '11 at 05:23
  • @iphoneFreak: i don't understand how to setup the heirarchy of UIViews for the static view and the subviews. I get that in the code, i would do something like self.view addSubView:SubView1 but i don't understand how to tell it to start at the x,y coordinate – Andrew Park Jul 20 '11 at 05:28
  • U specify the coordinates in the CGRectMake method for each UIView you are creating. Hope u got me. – stack2012 Jul 20 '11 at 05:36
  • @iphoneFreak: sorry about all the questions, but hopefully this is the last one. So i understand that CGRectMake will make a frame that I can make the dynamic area. But is there a function that lets do something like loadWithNib? or do i need to generate the content with code? – Andrew Park Jul 20 '11 at 05:42
  • You can generate the UIViews u need easily with the code. I am sorry, I dont kno tat much about using the Nib or IB stuff. – stack2012 Jul 20 '11 at 05:45

4 Answers4

0

You should perform the switch in your view controller. The static buttons can have their actions hooked up to that controller (in IB), which can have an outlet (in IB) to the subviews and perform the swap.

As for when you should use IB, see this question.

Community
  • 1
  • 1
jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • Thanks for the link. but i'm still confused about the subviews. So i have a View controller, with a View inside it which has all the buttons I need. for the subviews, would those be within the View? or same heirarchy as the view? – Andrew Park Jul 20 '11 at 05:04
0

You can do it from interface builder as well. You just need to take viewController from interface builder drag-n-drop to main window. assign IBAction to all buttons to add different viewController's view to main window just make their frame some smaller.

Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
0

You can also achieve it programatically. Just create another viewcontroller class (as many as u want). In the loadView method of it create a UIView in the coordinates where u want to add the subview in the current view. Now create an instance of this viewcontroller class in the currentview controller and add it as a subview. You will get the subview at the desired location.If u want to change it dynamically create as many views and then add them to the array and change them whenever the button is clicked. Hope this helps.

stack2012
  • 2,146
  • 2
  • 16
  • 23
0

if u want to change or views by click on button then u chose segmentcontrol switch. and cod for each segment like as when click on segment 0 then open first sub view and when click on segment1 then open second sub view. And make by default unselected so that ur static view will appear initially lunching of view.

ram
  • 1,193
  • 1
  • 15
  • 27