Stupid question about view changing and project templates

Discussion in 'iOS Development' started by Chicken, Jan 28, 2009.

  1. Chicken

    Chicken Retired Moderator

    Feb 17, 2008
    Likes Received:
    iPhone 5S
    1. How can I change a view if say a button is pressed ? And that view is contained in a xib file

    2. What project template should i use for this kind of application

    3. Should i create a view controller for each view if so how do i do that ? Do i nead to write class files in IB for both the controller and the view?

    Sorry for the questions but i have a good app idea and am really confused

    Thanks in advance
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Jan 25, 2008
    Likes Received:

    1. you'll have to have a view controller push another view controller.

    2. i like to pick window-based, so that it's simplistic as the app can get, then i build it up how i want it (i am not particularly fond of the organization that is standard in the view-based app).

    3. i write only the view controller class, and then set the view controller in the view xib's class to the one i wrote, that way i have access to it's methods and variables from IB.
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Sep 19, 2007
    Likes Received:

    In your interface for your viewController that will control the view, create something like this with your ivars
    IBOutlet UIButton *yourButton;
    Next, in the same interface file, with the rest of your function prototypes, add something like this:
    - (IBAction)yourButtonPressed:(id)sender;
    Save the file and go back to Interface Builder. Select the view controller whose interface you've just edited. In the Inspector, select the IBOutlet your created and drag it to your button. Do the same for the IBAction you created.

    Back in your view controller's source, in the implementation file, create your IBAction:
    - (IBAction)yourButtonPressed:(id)sender { //sender is the actual button, should you need to reference it
    [INDENT][/INDENT]//Do what you need to with your view
    [INDENT]2)[/INDENT]  The starter project is entirely up to you, but why not start with a view controller based project.  That way you've already a view controller you can use.  
    [INDENT]3)[/INDENT]  No, you shouldn't create a view controller for each view.  Create one for each group of views.  Example:  You have one main view that covers the screen, and in that there are three subviews.  In each of those subviews, there are three more subviews.  That'd be 13 view controllers if you view controllered each view.  Horrible.  Instead, have one view controller that controls that group of views.  Whatever controls that view controller can swap out view controllers as needed (usually a nav bar controller/tab bar controller/app controller).

Share This Page