I am following the book "Test-Driven iOS Development" by Graham Lee and came across this section that isn't well explained at all. The idea is not to instantiate UIWindow in the didFinishLaunchingWithOptions but rather using an IBOutlet and hook it to an UIWindow xib file. I can't get that working and can't find any example on the internet.
-(void)testWindowHasRootNavigationControllerAfterApplicationLaunch
{
XCTAssertEqualObjects(window.rootViewController, navigationController, @"App delegate's navigation controller should be the root VC");
}
@implementation iTagNewsAppDelegateTests
{
UIWindow *window;
UINavigationController *navigationController;
AppDelegate *appDelegate;
}
- (void)setUp {
window = [UIWindow new];
navigationController = [UINavigationController new];
appDelegate = [AppDelegate new];
appDelegate.window = window;
appDelegate.navigationController = navigationController;
}
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BrowseOverflowViewController *firstViewController =
[[BrowseOverflowViewController alloc] initWithNibName: nil bundle: nil];
TopicTableDataSource *dataSource = [[TopicTableDataSource alloc]
init];
[dataSource setTopics: [self topics]];
firstViewController.dataSource = dataSource;
self.navigationController.viewControllers =
[NSArray arrayWithObject: firstViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
@interface BrowseOverflowAppDelegate : NSObject <UIApplicationDelegate>
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
His full project is on GitHub. Is there any tutorial how to define a custom UIWindow? many thanks
Aucun commentaire:
Enregistrer un commentaire