Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

daproject

macrumors newbie
Original poster
May 29, 2013
12
0
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;
 
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.
 
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.

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

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

Dejo, pages 148-153 explains the process. A very confusing line is the following on page 153
If we were working
with a nib that contained a view inside a window, we wouldn’t need to make this change, but since
we’re creating this entire view hierarchy from scratch, we must manually adjust the view’s frame so it
snugs up against the bottom of the status bar

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.