2012年2月29日 星期三

iPhone APP view controller and nib coworking

At beginning of program execution, the "applicationDidFinishLaunching" in application delegate,
we create
1. a window by "UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];"
With finally display this window by "[window makeKeyAndVisible];"
2. After a window been created, we than create a view controller -- a simple view controller, a navigation controller, a tab controller or etc …
"viewController = [[MyViewController alloc] init];"
The view controller tiles the screen components like a text area or an image view within "loadView" protocol interface.
At the time view was constructed, the view is assigned to the window by "[window addSubview:nav.view];"
3. Specially for navigation controller, we have a code segment like
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[MyViewController alloc] init]];
[window addSubview:nav.view];
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This will attach a view controller under a navigation controller.


The three steps are necessary but "can be invisible", by applying complicate interface builder.
1. Simply create a view in "loadView"
"self.view = [[[NSBundle mainBundle] loadNibNamed:@"mainview" owner:self options:nil] lastObject];"
2. Apply to a view controller
"self.viewController = [[ViewTestNoStoryBoard1ViewController alloc] initWithNibName:@"MyViewController" bundle:nil];"
The 1 and 2 works the same, only with some different expression. The nib contains simple structure with a view or an additional view controller
3. Assign to info.plist
"Main nib file base name = MainWindow(.nib)"
With this way, we can add view controllers, navigation controller, application delegate and window into nib file.
*** Important notice *** With this method, the nib file will manage the calling of related view controller code defined in nib file "implicitly".
4. Assign to info.plist with story board
This is a new comer of xcode 4.2 and … I am still studying it.

沒有留言: