Skip to content

Instantly share code, notes, and snippets.

@zssz
Created November 19, 2010 12:20
Show Gist options
  • Save zssz/706446 to your computer and use it in GitHub Desktop.
Save zssz/706446 to your computer and use it in GitHub Desktop.
Swizzling navbar hide methods to tackle this bug http://screenr.com/UEc - No luck.
//
// UINavigationController+Swizzle.m
//
// Created by Zsombor Szabó on 11/19/10.
// Copyright 2010 IZE. All rights reserved.
//
#import "UINavigationController+Swizzle.h"
#import <objc/runtime.h>
#import <objc/message.h>
void SwizzleClassSelectors(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
@implementation UINavigationController (Swizzle)
- (void)_doNothingForSetNavigationBarHidden:(BOOL)hidden
{
NSLog(@"%s", __FUNCTION__);
}
- (void)_doNothingForSetNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated
{
NSLog(@"%s", __FUNCTION__);
}
+ (void)_setNavbarMethodsEnabled:(BOOL)enabled
{
static BOOL swizzled = NO;
if (enabled == NO)
{
if (swizzled == NO)
{
swizzled = YES;
SwizzleClassSelectors([UINavigationController class], @selector(setNavigationBarHidden:), @selector(_doNothingForSetNavigationBarHidden:));
SwizzleClassSelectors([UINavigationController class], @selector(setNavigationBarHidden:animated:), @selector(_doNothingForSetNavigationBarHidden:animated:));
}
}
else
{
if (swizzled == YES)
{
swizzled = NO;
SwizzleClassSelectors([UINavigationController class], @selector(_doNothingForSetNavigationBarHidden:), @selector(setDrawingEnabled:));
SwizzleClassSelectors([UINavigationController class], @selector(_doNothingForSetNavigationBarHidden:animated:), @selector(setNavigationBarHidden:animated:));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment