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 8170025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:02:28+00:00 2026-06-06T21:02:28+00:00

I have a UIControl subclass in my iOS App (I’m using iOS 4.3), and

  • 0

I have a UIControl subclass in my iOS App (I’m using iOS 4.3), and part of the subclass is a method called “setButtonColor:(UIColor)bc”. Whenever I call this method from my code, it works fine…but only if I use a built-in color like greenColor or redColor. If I use “colorWithRed:green:blue:alpha,” to make my own color it crashes with this message in the console:

-[UIDeviceRGBColor set]: message sent to deallocated instance 0x4e61560

Here’s the setButtonColor: method:

-(void)setButtonColor:(UIColor *)bc{
    buttonColor = bc;
    [self setNeedsDisplay];
}

If I remove the setNeedsDisplay, it doesn’t crash, but the button color doesn’t change like it’s supposed to. If anybody has any insight into why this is happening, I would really appreciate it, and if you need more details, just ask.

EDIT: I just looked into it a little more. In my -drawRect method, I call [buttonColor set]. By commenting that out, it no longer crashes, but again, it also doesn’t change the button’s color.

Thanks in advance,

thekmc

  • 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-06-06T21:02:30+00:00Added an answer on June 6, 2026 at 9:02 pm

    I assume that you’re not using ARC.

    When setting buttonColor = bc without retaining, buttonColor will become a dangling pointer when the current autorelease pool flushes (assuming it’s not retained elsewhere).

    [self setNeedsDisplay] will invoke drawRect: later and at that point, buttonColor may already have been deallocated which will crash your app when referring to it.

    The reason that it doesn’t crash for the static colors may be due to UIKit keeping ownership of these for later re-use.

    By retaining buttonColor after setting it to bc, you keep the ownership so that it’s still valid for drawRect:.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a subclass of UIControl called ToggleImageControl via the following code (with
I have a problem using the -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccesoryControlTapped:(UIControl *)control method. I
I have a view (actually, a UIControl) as part of my UIViewController. This view
I have a UIControl (or UIView, doesn't matter which) and this is covered by
(iPhone SDK 3.x:) I have a UIControl subclass that creates a different number of
I have the following error on a Ios 5 application using ARC: *** -[ViewDettaglio
I have a UIControl which implements the touches began method like so: - (void)touchesBegan:(NSSet
I have a UIControl subclass which follows the UIAccessibilityContainer informal protocol: it returns NO
I have this line of code: delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic',
I study iOS SDK using this book and in 4 Chapter, when it tells

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.