Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7044407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:24:21+00:00 2026-05-28T02:24:21+00:00

I define my own my own drawRect method and it is called on 4.2.1

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:24:22+00:00Added an answer on May 28, 2026 at 2:24 am

    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:

    #import <Foundation/Foundation.h>
    @interface UIView(Border)
    @end
    

    UIView+Border.m:

    #import "UIView+Border.h"
    #import <QuartzCore/QuartzCore.h>
    #import <objc/runtime.h>
    
    @implementation UIView(Border)
    
    - (id)swizzled_initWithFrame:(CGRect)frame
    {
        // This is the confusing part (article explains this line).
        id result = [self swizzled_initWithFrame:frame];
    
        // Safe guard: do we have an UIView (or something that has a layer)?
        if ([result respondsToSelector:@selector(layer)]) {
            // Get layer for this view.
            CALayer *layer = [result layer];
            // Set border on layer.
            layer.borderWidth = 2;
            layer.borderColor = [[UIColor redColor] CGColor];
        }
    
        // Return the modified view.
        return result;
    }
    
    - (id)swizzled_initWithCoder:(NSCoder *)aDecoder
    {
        // This is the confusing part (article explains this line).
        id result = [self swizzled_initWithCoder:aDecoder];
    
        // Safe guard: do we have an UIView (or something that has a layer)?
        if ([result respondsToSelector:@selector(layer)]) {
            // Get layer for this view.
            CALayer *layer = [result layer];
            // Set border on layer.
            layer.borderWidth = 2;
            layer.borderColor = [[UIColor blueColor] CGColor];
        }
    
        // Return the modified view.
        return result;
    }
    
    + (void)load
    {
        // The "+ load" method is called once, very early in the application life-cycle.
        // It's called even before the "main" function is called. Beware: there's no
        // autorelease pool at this point, so avoid Objective-C calls.
        Method original, swizzle;
    
        // Get the "- (id)initWithFrame:" method.
        original = class_getInstanceMethod(self, @selector(initWithFrame:));
        // Get the "- (id)swizzled_initWithFrame:" method.
        swizzle = class_getInstanceMethod(self, @selector(swizzled_initWithFrame:));
        // Swap their implementations.
        method_exchangeImplementations(original, swizzle);
    
        // Get the "- (id)initWithCoder:" method.
        original = class_getInstanceMethod(self, @selector(initWithCoder:));
        // Get the "- (id)swizzled_initWithCoder:" method.
        swizzle = class_getInstanceMethod(self, @selector(swizzled_initWithCoder:));
        // Swap their implementations.
        method_exchangeImplementations(original, swizzle);
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to define my own (very simple) exception class in Python 2.6, but
I'm trying to define my own exception class the easiest way, and this is
Apple allow us to define our own Logo image from simulator launch to execute
So I'm trying to define my own tree type in haskell, but I'm getting
Given that users must be able to define their own fields on an object,
I have a class that defines its own enum like this: public class Test
I would like to know whether it is possible to define own doxygen comment
How can i define my own event in jQuery?
It's possible to define your own custom templates for normal project types, such as
I'm trying to define my own operator in Io, and I'm having a hard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.