-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from nwdl/navigation-controller
Add more UINavigationController methods
- Loading branch information
Showing
11 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// UINavigationController+DLR.h | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 4/29/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UINavigationController (DLR) | ||
|
||
/** Returns true if the passed view controller is the first view controller in the | ||
stack of view controllers. This can be helpful in determining if the | ||
view controller needed to be popped or dismissed. */ | ||
- (BOOL)dlr_isFirstViewController:(UIViewController *)viewController; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UINavigationController+DLR.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 4/29/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import "UINavigationController+DLR.h" | ||
|
||
@implementation UINavigationController (DLR) | ||
|
||
- (BOOL)dlr_isFirstViewController:(UIViewController *)viewController { | ||
return self.viewControllers.firstObject == viewController; | ||
} | ||
|
||
@end |
17 changes: 17 additions & 0 deletions
17
DLRUIKit/source/UIViewController+DLRNavigationController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UIViewController+DLRNavigationController.h | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 4/29/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIViewController (DLRNavigationController) | ||
|
||
/** Returns a new navigation controller instance with this view controller as the | ||
root view controller. */ | ||
- (UINavigationController *)dlr_embedInsideNavigationController; | ||
|
||
@end |
17 changes: 17 additions & 0 deletions
17
DLRUIKit/source/UIViewController+DLRNavigationController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UIViewController+DLRNavigationController.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 4/29/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import "UIViewController+DLRNavigationController.h" | ||
|
||
@implementation UIViewController (DLRNavigationController) | ||
|
||
- (UINavigationController *)dlr_embedInsideNavigationController { | ||
return [[UINavigationController alloc] initWithRootViewController:self]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// UINavigationController+DLRTests.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 4/29/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "UINavigationController+DLR.h" | ||
|
||
@interface UINavigationController_DLRTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation UINavigationController_DLRTests | ||
|
||
#pragma mark - dlr_isFirstViewController: | ||
|
||
- (void)testIsFirstViewController { | ||
UIViewController *viewController = [[UIViewController alloc] init]; | ||
|
||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; | ||
|
||
XCTAssertEqual(navigationController.viewControllers.count, 1); | ||
XCTAssertEqual(navigationController.viewControllers.firstObject, viewController); | ||
|
||
XCTAssertTrue([navigationController dlr_isFirstViewController:viewController]); | ||
} | ||
|
||
- (void)testIsFirstViewControllerNot { | ||
UIViewController *firstViewController = [[UIViewController alloc] init]; | ||
|
||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; | ||
|
||
UIViewController *secondViewController = [[UIViewController alloc] init]; | ||
[navigationController pushViewController:secondViewController animated:NO]; | ||
|
||
XCTAssertEqual(navigationController.viewControllers.count, 2); | ||
XCTAssertEqual(navigationController.viewControllers[0], firstViewController); | ||
XCTAssertEqual(navigationController.viewControllers[1], secondViewController); | ||
|
||
XCTAssertFalse([navigationController dlr_isFirstViewController:secondViewController]); | ||
} | ||
|
||
@end |
30 changes: 30 additions & 0 deletions
30
DLRUIKitTests/source/UIViewController+DLRNavigationControllerTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// UIViewController+DLRNavigationControllerTests.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 4/29/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "UIViewController+DLRNavigationController.h" | ||
|
||
@interface UIViewController_DLRNavigationControllerTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation UIViewController_DLRNavigationControllerTests | ||
|
||
#pragma mark - dlr_embedInsideNavigationController | ||
|
||
- (void)testEmbedInsideNavigationController { | ||
UIViewController *viewController = [[UIViewController alloc] init]; | ||
|
||
UINavigationController *navigationController = [viewController dlr_embedInsideNavigationController]; | ||
|
||
XCTAssertEqual(navigationController.viewControllers.count, 1); | ||
XCTAssertEqual(navigationController.viewControllers.firstObject, viewController); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters