Skip to content

Commit

Permalink
Merge pull request #11 from nwdl/top-presented-view-controller
Browse files Browse the repository at this point in the history
add top presented view controller category
  • Loading branch information
nwdl committed May 26, 2015
2 parents 10df9c1 + 89606de commit 37d375a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DLRUIKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DLRUIKit"
s.version = "1.3.0"
s.version = "1.4.0"
s.summary = "A collection of UIKit categories."
s.homepage = "https://github.com/detroit-labs/dlr-uikit-ios"
s.license = 'MIT'
Expand Down
12 changes: 12 additions & 0 deletions DLRUIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
433C59FD1AC335BE0014EFB8 /* DLRLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 433C59FB1AC335BE0014EFB8 /* DLRLayoutConstraint.m */; };
433C5A001AC336B10014EFB8 /* DLRLayoutConstraintTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 433C59FF1AC336B10014EFB8 /* DLRLayoutConstraintTests.m */; };
433C5A041AC338250014EFB8 /* LayoutConstraintViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 433C5A031AC338250014EFB8 /* LayoutConstraintViewController.m */; };
435C37501B151C98003A0910 /* UIViewController+DLRPresentedViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 435C374E1B151C98003A0910 /* UIViewController+DLRPresentedViewController.h */; };
435C37511B151C98003A0910 /* UIViewController+DLRPresentedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 435C374F1B151C98003A0910 /* UIViewController+DLRPresentedViewController.m */; };
435C37531B151DA9003A0910 /* UIViewController+DLRPresentedViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 435C37521B151DA9003A0910 /* UIViewController+DLRPresentedViewControllerTests.m */; };
4362BDC01A8ABA5900B3A89E /* UIDevice+DLR.h in Headers */ = {isa = PBXBuildFile; fileRef = 4362BDBE1A8ABA5900B3A89E /* UIDevice+DLR.h */; };
4362BDC11A8ABA5900B3A89E /* UIDevice+DLR.m in Sources */ = {isa = PBXBuildFile; fileRef = 4362BDBF1A8ABA5900B3A89E /* UIDevice+DLR.m */; };
4362BDC31A8AC0C400B3A89E /* UIDevice+DLRTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4362BDC21A8AC0C400B3A89E /* UIDevice+DLRTests.m */; };
Expand Down Expand Up @@ -115,6 +118,9 @@
433C59FF1AC336B10014EFB8 /* DLRLayoutConstraintTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DLRLayoutConstraintTests.m; sourceTree = "<group>"; };
433C5A021AC338250014EFB8 /* LayoutConstraintViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutConstraintViewController.h; sourceTree = "<group>"; };
433C5A031AC338250014EFB8 /* LayoutConstraintViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LayoutConstraintViewController.m; sourceTree = "<group>"; };
435C374E1B151C98003A0910 /* UIViewController+DLRPresentedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+DLRPresentedViewController.h"; sourceTree = "<group>"; };
435C374F1B151C98003A0910 /* UIViewController+DLRPresentedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+DLRPresentedViewController.m"; sourceTree = "<group>"; };
435C37521B151DA9003A0910 /* UIViewController+DLRPresentedViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+DLRPresentedViewControllerTests.m"; sourceTree = "<group>"; };
4362BDBE1A8ABA5900B3A89E /* UIDevice+DLR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+DLR.h"; sourceTree = "<group>"; };
4362BDBF1A8ABA5900B3A89E /* UIDevice+DLR.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+DLR.m"; sourceTree = "<group>"; };
4362BDC21A8AC0C400B3A89E /* UIDevice+DLRTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+DLRTests.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -408,6 +414,8 @@
4388EE151AF11E9100CD2140 /* UIViewController+DLRNavigationController.m */,
439373621A8521A800A552D5 /* UIViewController+DLRParentViewController.h */,
439373631A8521A800A552D5 /* UIViewController+DLRParentViewController.m */,
435C374E1B151C98003A0910 /* UIViewController+DLRPresentedViewController.h */,
435C374F1B151C98003A0910 /* UIViewController+DLRPresentedViewController.m */,
439373641A8521A800A552D5 /* UIWebView+DLRViewport.h */,
439373651A8521A800A552D5 /* UIWebView+DLRViewport.m */,
);
Expand All @@ -428,6 +436,7 @@
439373791A85220F00A552D5 /* UIView+DLRRoundedCornersTests.m */,
4388EE181AF11F0200CD2140 /* UIViewController+DLRNavigationControllerTests.m */,
4393737A1A85220F00A552D5 /* UIViewController+DLRParentViewControllerTests.m */,
435C37521B151DA9003A0910 /* UIViewController+DLRPresentedViewControllerTests.m */,
4393737B1A85220F00A552D5 /* UIWebView+DLRViewportTests.m */,
);
name = "Category Tests";
Expand Down Expand Up @@ -465,6 +474,7 @@
4362BDC01A8ABA5900B3A89E /* UIDevice+DLR.h in Headers */,
439373661A8521A800A552D5 /* UIApplication+DLRLocalNotifications.h in Headers */,
4393736C1A8521A800A552D5 /* UIView+DLRLayoutConstraints.h in Headers */,
435C37501B151C98003A0910 /* UIViewController+DLRPresentedViewController.h in Headers */,
4393736E1A8521A800A552D5 /* UIView+DLRRoundedCorners.h in Headers */,
439373701A8521A800A552D5 /* UIViewController+DLRParentViewController.h in Headers */,
43B4C20D1A8C19C300680976 /* UIViewController+DLRStoryboardManager.h in Headers */,
Expand Down Expand Up @@ -633,6 +643,7 @@
4388EE111AF11DA400CD2140 /* UINavigationController+DLR.m in Sources */,
439373731A8521A800A552D5 /* UIWebView+DLRViewport.m in Sources */,
439373691A8521A800A552D5 /* UIColor+DLR.m in Sources */,
435C37511B151C98003A0910 /* UIViewController+DLRPresentedViewController.m in Sources */,
439373671A8521A800A552D5 /* UIApplication+DLRLocalNotifications.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -652,6 +663,7 @@
4393737D1A85220F00A552D5 /* UIColor+DLRTests.m in Sources */,
4393737C1A85220F00A552D5 /* UIApplication+DLRLocalNotificationsTests.m in Sources */,
439373821A85220F00A552D5 /* UIWebView+DLRViewportTests.m in Sources */,
435C37531B151DA9003A0910 /* UIViewController+DLRPresentedViewControllerTests.m in Sources */,
433C5A001AC336B10014EFB8 /* DLRLayoutConstraintTests.m in Sources */,
439373811A85220F00A552D5 /* UIViewController+DLRParentViewControllerTests.m in Sources */,
439373801A85220F00A552D5 /* UIView+DLRRoundedCornersTests.m in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions DLRUIKit/source/UIViewController+DLRPresentedViewController.h
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 DLRUIKit/source/UIViewController+DLRPresentedViewController.m
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
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,10 @@ layoutConstraint.constant = -10;
root view controller. */
- (UINavigationController *)dlr_embedInsideNavigationController;
```

### UIViewController+DLRPresentedViewController Category Examples

```objc
/** Returns the top most presented view controller, which could be this view controller. */
- (UIViewController *)dlr_topPresentedViewController;
```

0 comments on commit 37d375a

Please sign in to comment.