You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/07/10 00:40:20 UTC

[4/7] ios commit: Adds a way for CordovaLibApp to recreate the ViewController.

Adds a way for CordovaLibApp to recreate the ViewController.

This does not change the behaviour of CordovaLibApp when run directly,
but causes the root ViewController to not be created automatically when
running the unit tests. The intention here is that unit tests that
require a full ViewController will use the methods to create it and
destroy it afterwards.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/4facac44
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/4facac44
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/4facac44

Branch: refs/heads/master
Commit: 4facac446609da22bc84214707919093d022cb7c
Parents: 16d50f2
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 6 09:27:52 2012 -0400
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Jul 9 14:31:34 2012 -0700

----------------------------------------------------------------------
 CordovaLib/CordovaLibApp/AppDelegate.h |    3 ++
 CordovaLib/CordovaLibApp/AppDelegate.m |   30 ++++++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4facac44/CordovaLib/CordovaLibApp/AppDelegate.h
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLibApp/AppDelegate.h b/CordovaLib/CordovaLibApp/AppDelegate.h
index b832c3d..65a80fc 100644
--- a/CordovaLib/CordovaLibApp/AppDelegate.h
+++ b/CordovaLib/CordovaLibApp/AppDelegate.h
@@ -27,4 +27,7 @@
 
 @property (strong, nonatomic) ViewController *viewController;
 
+- (void)createViewController;
+- (void)destroyViewController;
+
 @end

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4facac44/CordovaLib/CordovaLibApp/AppDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLibApp/AppDelegate.m b/CordovaLib/CordovaLibApp/AppDelegate.m
index e66a21f..81d2fe0 100644
--- a/CordovaLib/CordovaLibApp/AppDelegate.m
+++ b/CordovaLib/CordovaLibApp/AppDelegate.m
@@ -33,13 +33,8 @@
     [super dealloc];
 }
 
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
-{
-    
-    CGRect screenBounds = [[UIScreen mainScreen] bounds];
-    self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
-    self.window.autoresizesSubviews = YES;
-    
+- (void)createViewController {
+    NSAssert(!self.viewController, @"ViewController already created.");
     CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
     
     self.viewController = [[[ViewController alloc] init] autorelease];
@@ -49,6 +44,27 @@
     self.viewController.view.frame = viewBounds;
 
     self.window.rootViewController = self.viewController;
+}
+
+- (void)destroyViewController {
+    // Clean up circular refs so that the view controller will actully be released.
+    [self.viewController dispose];
+    self.viewController = nil;
+    self.window.rootViewController = nil;
+}
+
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{    
+    CGRect screenBounds = [[UIScreen mainScreen] bounds];
+    self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
+    self.window.autoresizesSubviews = YES;
+    
+    // Create the main view on start-up only when not running unit tests.
+    if (!NSClassFromString(@"CDVWebViewTest")) {
+        [self createViewController];
+    }
+    
     [self.window makeKeyAndVisible];
 
     return YES;