-
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 #11 from nwdl/top-presented-view-controller
add top presented view controller category
- Loading branch information
Showing
6 changed files
with
103 additions
and
1 deletion.
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
16 changes: 16 additions & 0 deletions
16
DLRUIKit/source/UIViewController+DLRPresentedViewController.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,16 @@ | ||
// | ||
// UIViewController+DLRPresentedViewController.h | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 5/26/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIViewController (DLRPresentedViewController) | ||
|
||
/** Returns the top most presented view controller, which could be this view controller. */ | ||
- (UIViewController *)dlr_topPresentedViewController; | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
DLRUIKit/source/UIViewController+DLRPresentedViewController.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,23 @@ | ||
// | ||
// UIViewController+DLRPresentedViewController.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 5/26/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import "UIViewController+DLRPresentedViewController.h" | ||
|
||
@implementation UIViewController (DLRPresentedViewController) | ||
|
||
- (UIViewController *)dlr_topPresentedViewController { | ||
UIViewController *topPresentedViewController = self; | ||
|
||
while (topPresentedViewController.presentedViewController) { | ||
topPresentedViewController = topPresentedViewController.presentedViewController; | ||
} | ||
|
||
return topPresentedViewController; | ||
} | ||
|
||
@end |
44 changes: 44 additions & 0 deletions
44
DLRUIKitTests/source/UIViewController+DLRPresentedViewControllerTests.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,44 @@ | ||
// | ||
// UIViewController+DLRPresentedViewControllerTests.m | ||
// DLRUIKit | ||
// | ||
// Created by Nate Walczak on 5/26/15. | ||
// Copyright (c) 2015 Detroit Labs, LLC. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "UIViewController+DLRPresentedViewController.h" | ||
|
||
@interface UIViewController_DLRPresentedViewControllerTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation UIViewController_DLRPresentedViewControllerTests | ||
|
||
#pragma mark - dlr_topPresentedViewController: | ||
|
||
- (void)testTopPresentedViewControllerWithModalViewController { | ||
UIViewController *rootViewController = [[UIViewController alloc] init]; | ||
|
||
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; | ||
keyWindow.rootViewController = rootViewController; | ||
|
||
UIViewController *firstModalViewController = [[UIViewController alloc] init]; | ||
[rootViewController presentViewController:firstModalViewController animated:NO completion:nil]; | ||
|
||
UIViewController *topPresentedViewController = [rootViewController dlr_topPresentedViewController]; | ||
XCTAssertEqual(topPresentedViewController, firstModalViewController); | ||
} | ||
|
||
- (void)testTopPresentedViewControllerWithoutModalViewController { | ||
UIViewController *rootViewController = [[UIViewController alloc] init]; | ||
|
||
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; | ||
keyWindow.rootViewController = rootViewController; | ||
|
||
UIViewController *topPresentedViewController = [rootViewController dlr_topPresentedViewController]; | ||
XCTAssertEqual(topPresentedViewController, rootViewController); | ||
} | ||
|
||
@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