Просмотр исходного кода

*Added the ability to determine a UIView's view controller without selection the view controller's view delegate.

nin9tyfour лет назад: 10
Родитель
Сommit
b564c25d2a

+ 16 - 1
Classes/ObjectExplorers/FLEXViewExplorerViewController.m

@@ -15,7 +15,8 @@
 
 typedef NS_ENUM(NSUInteger, FLEXViewExplorerRow) {
     FLEXViewExplorerRowViewController,
-    FLEXViewExplorerRowPreview
+    FLEXViewExplorerRowPreview,
+    FLEXViewExplorerRowViewControllerForAncestor
 };
 
 @interface FLEXViewExplorerViewController ()
@@ -46,6 +47,8 @@ typedef NS_ENUM(NSUInteger, FLEXViewExplorerRow) {
     
     if ([FLEXUtility viewControllerForView:self.viewToExplore]) {
         [rowCookies addObject:@(FLEXViewExplorerRowViewController)];
+    }else{
+        [rowCookies addObject:@(FLEXViewExplorerRowViewControllerForAncestor)];
     }
     
     [rowCookies addObject:@(FLEXViewExplorerRowPreview)];
@@ -79,6 +82,10 @@ typedef NS_ENUM(NSUInteger, FLEXViewExplorerRow) {
             case FLEXViewExplorerRowPreview:
                 title = @"Preview Image";
                 break;
+            
+            case FLEXViewExplorerRowViewControllerForAncestor:
+                title = @"View Controller For Ancestor";
+                break;
         }
     } else if ([rowCookie isKindOfClass:[NSString class]]) {
         objc_property_t property = [self viewPropertyForName:rowCookie];
@@ -105,6 +112,10 @@ typedef NS_ENUM(NSUInteger, FLEXViewExplorerRow) {
                 
             case FLEXViewExplorerRowPreview:
                 break;
+            
+            case FLEXViewExplorerRowViewControllerForAncestor:
+                subtitle = [FLEXRuntimeUtility descriptionForIvarOrPropertyValue:[FLEXUtility viewControllerForAncestralView:self.viewToExplore]];
+                break;
         }
     } else if ([rowCookie isKindOfClass:[NSString class]]) {
         objc_property_t property = [self viewPropertyForName:rowCookie];
@@ -141,6 +152,10 @@ typedef NS_ENUM(NSUInteger, FLEXViewExplorerRow) {
             case FLEXViewExplorerRowPreview:
                 drillInViewController = [[self class] imagePreviewViewControllerForView:self.viewToExplore];
                 break;
+                
+            case FLEXViewExplorerRowViewControllerForAncestor:
+                drillInViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:[FLEXUtility viewControllerForAncestralView:self.viewToExplore]];
+                break;
         }
     } else if ([rowCookie isKindOfClass:[NSString class]]) {
         objc_property_t property = [self viewPropertyForName:rowCookie];

+ 1 - 0
Classes/Utility/FLEXUtility.h

@@ -18,6 +18,7 @@
 + (NSString *)descriptionForView:(UIView *)view includingFrame:(BOOL)includeFrame;
 + (NSString *)stringForCGRect:(CGRect)rect;
 + (UIViewController *)viewControllerForView:(UIView *)view;
++ (UIViewController *)viewControllerForAncestralView:(UIView *)view;
 + (NSString *)detailDescriptionForView:(UIView *)view;
 + (UIImage *)circularImageWithColor:(UIColor *)color radius:(CGFloat)radius;
 + (UIColor *)scrollViewGrayColor;

+ 12 - 0
Classes/Utility/FLEXUtility.m

@@ -58,6 +58,18 @@
     return viewController;
 }
 
++ (UIViewController *)viewControllerForAncestralView:(UIView *)view{
+    UIViewController *viewController = nil;
+    SEL viewDelSel = NSSelectorFromString([NSString stringWithFormat:@"%@ewControllerForAncestor", @"_vi"]);
+    if ([view respondsToSelector:viewDelSel]) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+        viewController = [view performSelector:viewDelSel];
+#pragma clang diagnostic pop
+    }
+    return viewController;
+}
+
 + (NSString *)detailDescriptionForView:(UIView *)view
 {
     return [NSString stringWithFormat:@"frame %@", [self stringForCGRect:view.frame]];