Permalink
Browse files

initial support for swizzling the methods we'll need to use & impleme…

…nt custom_viewWillMoveToSuperView
  • Loading branch information...
1 parent 3cb9998 commit 818f6e017546f39977eca2046f8fb71d26f50489 @Machx committed Oct 30, 2012
Showing with 70 additions and 2 deletions.
  1. +70 −2 Rebel/NSView+RBLViewControllerAdditions.m
@@ -7,14 +7,16 @@
//
#import "NSView+RBLViewControllerAdditions.h"
+#import "RBLViewController.h"
+#import "NSObject+RBObjectSizzlingAdditions.h"
#import <objc/runtime.h>
void *kRBLViewControllerKey = &kRBLViewControllerKey;
-static BOOL hasSwizzledMethods = NO;
-
@implementation NSView (NSView_RBLViewControllerAdditions)
+#pragma mark - ViewController
+
-(id)viewController
{
return objc_getAssociatedObject(self, kRBLViewControllerKey);
@@ -37,4 +39,70 @@ -(void)setViewController:(id)newViewController
}
}
+#pragma mark - Custom Methods
+
++(void)loadSupportForRBLViewControllers
+{
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ //swizzle swizzle...
+ [self swapMethod:@selector(viewWillMoveToSuperview:) with:@selector(custom_viewWillMoveToSuperview:)];
+ [self swapMethod:@selector(viewDidMoveToSuperview) with:@selector(custom_viewDidMoveToSuperview)];
+
+ [self swapMethod:@selector(viewWillMoveToWindow:) with:@selector(custom_viewWillMoveToWindow:)];
+ [self swapMethod:@selector(viewDidMoveToWindow) with:@selector(custom_viewDidMoveToWindow)];
+
+ [self swapMethod:@selector(setNextResponder:) with:@selector(custom_setNextResponder:)];
+ });
+}
+
+- (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview
+{
+ [self custom_viewWillMoveToSuperview:newSuperview];
+
+ if ([self.viewController isKindOfClass:[RBLViewController class]]) {
+ if (newSuperview == nil) {
+ [(RBLViewController *)self.viewController viewWillBeRemovedFromSuperview];
+
+ if ((self.superview != nil) && (self.window != nil)) {
+ [(RBLViewController *)self.viewController viewWillDisappear];
+ }
+ } else {
+ [(RBLViewController *)self.viewController viewWillMoveToSuperview:newSuperview];
+
+ if (self.window != nil) {
+ [(RBLViewController *)self.viewController viewWillAppear];
+ }
+ }
+ }
+}
+
+- (void)custom_viewDidMoveToSuperview
+{
+ [self custom_viewDidMoveToSuperview];
+
+
+}
+
+- (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow
+{
+ [self custom_viewWillMoveToWindow:newWindow];
+
+
+}
+
+- (void)custom_viewDidMoveToWindow
+{
+ [self custom_viewDidMoveToWindow];
+
+
+}
+
+- (void)custom_setNextResponder:(NSResponder *)newNextResponder
+{
+ [self custom_setNextResponder:newNextResponder];
+
+
+}
+
@end

0 comments on commit 818f6e0

Please sign in to comment.