Explorar o código

Added ability to add UIViewController based user defined global enties.

Mikhail Solodovnichenko %!s(int64=11) %!d(string=hai) anos
pai
achega
1653d86552

+ 9 - 0
Classes/Explorer Toolbar/FLEXManager.h

@@ -23,9 +23,18 @@
 /// @param entryName The string to be displayed in the cell.
 /// @param objectFutureBlock When you tap on the row, information about the object returned by this block will be displayed.
 /// Passing a block that returns an object allows you to display information about an object whose actual pointer may change at runtime (e.g. +currentUser)
+/// @param forceObjectExplorer Specifies how to interpret object returned from objectFutureBlock. If YES it will create object/class inspector view controller
+/// for any supplied object, while NO will cause any passed UIViewController subclasses to be pushed into manager's navigation view controller.
 /// @note This method must be called from the main thread.
 /// The objectFutureBlock will be invoked from the main thread and may return nil.
 /// @note The passed block will be copied and retain for the duration of the application, you may want to use __weak references.
+- (void)registerGlobalEntryWithName:(NSString *)entryName
+                  objectFutureBlock:(id (^)(void))objectFutureBlock
+                forceObjectExplorer:(BOOL)forceObjectExplorer;
+
+/**
+ *  The same as -registerGlobalEntryWithName:objectFutureBlock:forceObjectExplorer: passing YES for forceObjectExplorer.
+ */
 - (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id(^)(void))objectFutureBlock;
 
 @end

+ 18 - 1
Classes/Explorer Toolbar/FLEXManager.m

@@ -12,6 +12,7 @@
 #import "FLEXGlobalsTableViewControllerEntry.h"
 #import "FLEXObjectExplorerFactory.h"
 #import "FLEXObjectExplorerViewController.h"
+#import <objc/runtime.h>
 
 @interface FLEXManager () <FLEXWindowEventDelegate, FLEXExplorerViewControllerDelegate>
 
@@ -102,6 +103,13 @@
 #pragma mark - Extensions
 
 - (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock
+{
+    [self registerGlobalEntryWithName:entryName objectFutureBlock:objectFutureBlock forceObjectExplorer:YES];
+}
+
+- (void)registerGlobalEntryWithName:(NSString *)entryName
+                  objectFutureBlock:(id (^)(void))objectFutureBlock
+                forceObjectExplorer:(BOOL)forceObjectExplorer
 {
     NSParameterAssert(entryName);
     NSParameterAssert(objectFutureBlock);
@@ -111,7 +119,16 @@
     FLEXGlobalsTableViewControllerEntry *entry = [FLEXGlobalsTableViewControllerEntry entryWithNameFuture:^NSString *{
         return entryName;
     } viewControllerFuture:^UIViewController *{
-        return [FLEXObjectExplorerFactory explorerViewControllerForObject:objectFutureBlock()];
+        id object = objectFutureBlock();
+
+        if([object_getClass(object) isSubclassOfClass:[UIViewController class]] && forceObjectExplorer == NO)
+        {
+            return object;
+        }
+        else
+        {
+            return [FLEXObjectExplorerFactory explorerViewControllerForObject:object];
+        }
     }];
 
     [self.userGlobalEntries addObject:entry];

+ 38 - 1
Example/UICatalog/AAPLCatalogTableTableViewController.m

@@ -12,7 +12,7 @@
 #endif
 
 @interface AAPLCatalogTableTableViewController ()
-
+- (void)registerViewControllerBasedOption;
 @end
 
 @implementation AAPLCatalogTableTableViewController
@@ -22,6 +22,7 @@
     [super viewDidLoad];
     
 #if DEBUG
+    [self registerViewControllerBasedOption];
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"FLEX" style:UIBarButtonItemStylePlain target:self action:@selector(flexButtonTapped:)];
 #endif
 }
@@ -34,4 +35,40 @@
 #endif
 }
 
+- (void)registerViewControllerBasedOption
+{
+    // create UIViewController subclass
+    UIViewController *viewController = [[UIViewController alloc] init];
+
+    // fill it with some stuff
+    UILabel *infoLabel = [[UILabel alloc] init];
+    infoLabel.translatesAutoresizingMaskIntoConstraints = NO;
+    infoLabel.text = @"Add switches, notes or whatewer you wish to provide your testers with superpowers!";
+    infoLabel.numberOfLines = 0;
+    infoLabel.textAlignment = NSTextAlignmentCenter;
+
+    UIView *view = viewController.view;
+    view.backgroundColor = [UIColor whiteColor];
+    [view addSubview:infoLabel];
+
+    [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[infoLabel]-0-|"
+                                                                 options:0
+                                                                 metrics:nil
+                                                                   views:NSDictionaryOfVariableBindings(infoLabel)]];
+
+    [view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[infoLabel]-0-|"
+                                                                 options:0
+                                                                 metrics:nil
+                                                                   views:NSDictionaryOfVariableBindings(infoLabel)]];
+
+
+
+    // return it in objectFutureBlock
+    [[FLEXManager sharedManager] registerGlobalEntryWithName:@"Custom superpowers"
+                                           objectFutureBlock:^id{
+                                               return viewController;
+                                           }
+                                         forceObjectExplorer:NO];
+}
+
 @end