creating an empty project and setting up basics

Discussion in 'iOS Programming' started by daproject, May 29, 2013.

  1. daproject macrumors newbie

    Joined:
    May 29, 2013
    #1
    Hi Forum,

    Clearly we can easily make a single view application which XCODE supplies us with nib files and one ViewController. I would like to know what a user has to do if he/she wants to start out with an EMPTY project and do all the preparation manually. This is solely for learning clearly not a practical thing. I have read a tutorial on it and it basically says:

    step 1: create empty project

    step 2: add the following to the appdelegate.h
    Code:
    @class BIDSwitchViewController;
    @property (strong, nonatomic) BIDSwitchViewController *switchViewController;
    
    step 3: create a view ( nib file)

    step 4: Add the following to the - (BOOL)application: (UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method

    Code:
    self.switchViewController = [[BIDSwitchViewController alloc]initWithNibName:@"SwitchView" bundle:nil];
        UIView *switchView = self.switchViewController.view;
        CGRect switchViewFrame = switchView.frame;
        switchViewFrame.origin.y = switchViewFrame.origin.y + [UIApplication sharedApplication].statusBarFrame.size.height;
        switchView.frame = switchViewFrame;
        
        self.window.rootViewController = self.switchViewController;
    step 5: update file Owner to the name of the viewcontroller class

    step 6: connect view object in nib to fileowner


    My question is:

    are the following lines necessary? if so why?


    Code:
    UIView *switchView = self.switchViewController.view;
        CGRect switchViewFrame = switchView.frame;
        switchViewFrame.origin.y = switchViewFrame.origin.y + [UIApplication sharedApplication].statusBarFrame.size.height;
        switchView.frame = switchViewFrame;
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Have you tried removing those lines and seeing what happens?

    It looks to me like that code will move the view down so that none of it is covered by the status bar. It seems to me that potentially the bottom portion of the view will no longer be visible because it'll be off the bottom of the screen, but I'm not sure about that.
     
  3. daproject thread starter macrumors newbie

    Joined:
    May 29, 2013
    #3
    Hi, Yes i tried removing it , and it SEEMS to be as if it makes no diff. I know im knit picking at this but I guess i like to know how things really work
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Which tutorial?
     
  5. daproject thread starter macrumors newbie

    Joined:
    May 29, 2013
    #5
    Apress Beginning iOS 6 development. Do you have that book dejo?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    If you mean "Beginning iOS 6 Development" by David Mark, Jack Nutting, Jeff LaMarche, and Fredrik Olsson, yes, I have that book. What chapter / page number(s) are you referring to?
     
  7. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #7
    Be careful with assumptions. As dejo says, that code seems to be adapting the view size for status bar/no status bar.

    In order to tell if it's needed, you would need to run the code on an app that uses a status bar and one that does not, with content at the very top and very bottom of the window so you could see if you were clipping 20 pixels, and test in portrait and landscape mode.

    I applaud you for wanting to learn how things "really" work, but don't drive yourself crazy by having to take apart and understand every little detail of everything. If you do that you'll never get past the starting line.

    Modern OSes and modern application frameworks are so rich and complex that I don't think any one person can possibly know everything about the platform, and that includes senior engineers at Apple. You have to pick and choose the things you focus on.

    Getting your windows, view controllers, views, delegates, outlets, etc hooked up correctly is one of those fussy things that can drive you nuts. It's easy to miss something and have an app that should work, but doesn't.

    The templates do that messy, error-prone setup for you. Before they existed, I spent a lot of time pulling my hair out because I forgot something like hooking up a view controllers "view" property, and the "delegate" property, and stuff like that.
     
  8. daproject thread starter macrumors newbie

    Joined:
    May 29, 2013
    #8
    Dejo, pages 148-153 explains the process. A very confusing line is the following on page 153
    selecting a "view" file from the User interface choices when adding a new file gives you a view. So why does it say "IF we were working with a nib that contained a view"

    Also what is the difference between what the do here VS starting on page 176 where they select an "empty" IB template, where you see a "window" vs a "view" on the dock.
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    I was going to suggest asking the book's authors but it looks like you've already started a thread on their forums. Perhaps it would be better suited to pursue this query over there.

    P.S. It is considered impolite to cross-post questions.
     

Share This Page