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

  • Home
  • SEARCH
  • 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 6064103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:14:38+00:00 2026-05-23T09:14:38+00:00

I trying to extend UIButton but I keep getting a EXC_BAD_ACCESS, inside the initializer

  • 0

I trying to extend UIButton but I keep getting a “EXC_BAD_ACCESS”, inside the initializer of ColorButton’s implementation file.

Header of ColorButton.

#import <Foundation/Foundation.h>


@interface ColorButton : UIButton {
    UIImage * originalImage;
}

@property (nonatomic,readonly) NSString * buttonName;

-(id) initButtonWithName:(NSString *) color;
-(void) setOriginalImage;
-(void) setImage:(UIImage *) image;
@end

ColorButton Implementation

#import "ColorButton.h"

@implementation ColorButton

@synthesize buttonName;

-(id) initButtonWithName:(NSString *) color {
    if ((self = (ColorButton *)[UIButton buttonWithType:UIButtonTypeCustom])) {
        buttonName = color;
        [self setTitle:buttonName forState:UIControlStateNormal]; //This is the line of the "EXC_BAD_ACCESS" error.
        [self setBackgroundImage:[self backgroundImageForDevice:color] forState:UIControlStateNormal]; // This line gets the error too. If I comment the line before it out.
    }
    return self;
}

-(UIImage *) backgroundImageForDevice:(NSString *) color {
        color = [color stringByAppendingString:@"Bubble"];
    if ([[[UIDevice currentDevice] model] isEqualToString:@"iPad"] ||[[[UIDevice currentDevice] model] isEqualToString:@"iPad Simulator"]) {
        color = [color stringByAppendingString:@"-iPad"];
    }
    color = [color stringByAppendingString:@".png"];
    return [UIImage imageNamed:color];
}

-(void) setOriginalImage {
    [self setBackgroundImage:originalImage forState:UIControlStateNormal];
}

-(void) setImage:(UIImage *) image {
    [self setImage:image forState:UIControlStateNormal];
}
@end
  • 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-23T09:14:38+00:00Added an answer on May 23, 2026 at 9:14 am

    You can not cast a UIButton * instance to a ColorButton * type.

    You have to remember that you ColorButton inherits from UIButton and not the other way, this means that every instance of ColorButton is a UIButton by definition, but the opposite is not true.

    Here is another thread that has the exact same issue 🙂

    objective C: Buttons created from subclass of UIButton class not working

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

Sidebar

Related Questions

I'm trying to extend the TextBox , ComboBox and Panel controls using IExtenderProvider but
I'm trying to extend JButton with Clojure, but I ran into a problem when
I'm trying to extend a form and add an upload file field from within
I'm trying to extend the SPL ArrayObject but I've hit a little snag. Using
I'm trying to extend the GridView class to always show the header and footer
I was trying to extend the shape class to contain an additional variable but
Simply trying to extend View and do some custom work, but Eclipse will complain
I am trying to extend my company specific BaseClass (Acme::BaseClass) but whenever I: package
I'm trying to extend an assoc array like this, but PHP doesn't like it.
I am trying to extend dijit.form.Button with an extra attribute but this is not

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.