I define my own my own drawRect method and it is called on 4.2.1 (iOS) 5.0 (iOS) and 4.3.2 (Simulator) sucesfully. But it never called on 3.1.3 (iPhone 2g).
What reason could be for this?
P.S. Since i start write the question i think about my 3.1.3 device is jailbroken. Maybe it is root cause of this strange behaviour.
Upd: To reproduce issue i use next code:
@implementation UIView (MyOwnCategory)
- (void)drawRect:(CGRect)rect
{
const char * function = __FUNCTION__;
[NSException raise: @"hi!" format: @"%s", function];
}
@end
exception never happened on 3.1.3 even when i call [super drawRect: rect]
explicitly
I wanted to write about Method Swizzling for a few weeks now, and @Kevin Ballard's comment finally made me do it (thank you for the inspiration, Kevin).
So here's a solution for your problem using method swizzling which should also work on iOS 3.x:
UIView+Border.h:
UIView+Border.m: