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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:18:44+00:00 2026-06-18T17:18:44+00:00

I have a custom button class: CustomButton.h file: @interface CustomButton : UIButton @property (nonatomic,

  • 0

I have a custom button class:

CustomButton.h file:

@interface CustomButton : UIButton
@property (nonatomic, retain) NSString* info;
@end

CustomButton.m file:

#import "CustomButton.h"

@implementation CustomButton

@synthesize info;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

@end

In my main view controller:

CustomButton* btn = [CustomButton buttonWithType:UIButtonTypeDetailDisclosure];

[btn setInfo:@"foobar"];
NSLog(@"%@", [btn info]);

[self.view addSubview:btn];

If it’s just a simple button ([CustomButton new]) I don’t get any error. But if I choose buttonWithType:UIButtonTypeDetailDisclosure I get this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UIButton setInfo:]: unrecognized selector sent to instance 0x753c8c0'

Why is this happening?

  • 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-18T17:18:45+00:00Added an answer on June 18, 2026 at 5:18 pm

    As soon as UIButton does not provide initWithType: method – you can’t subclass a "typed" button. You can’t create an extension for a library class either.
    The only way to "attach" something to a predefined object is to use associated objects:

    #import <objc/runtime.h>
        
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    NSString* info = @"foobar";
    objc_setAssociatedObject(btn, "info", info, OBJC_ASSOCIATION_RETAIN);
    //Later somewhere
    NSString* btnInfo = (NSString*)objc_getAssociatedObject(btn, "info");
    

    The "info" can be any string you like, it’s just a key to retrieve that object later.
    OBJC_ASSOCIATION_RETAIN means that the object would be retained and automatically released after the btn object’s dealloc: would be called. You can find more details about that here.

    The other way to solve your issue is to subclass the UIButton, add your info property and make it look like disclosure button by setting custom image with setImage:forState: method.

    Generally, coupling some data with standard UI controls is a sign of a bad architecture. Maybe you’ll make a little step backwards and try to find some other way to pass that string wherether you need to use it?

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

Sidebar

Related Questions

I have a custom ButtonUI class that paints the button. Before drawing the text,
I have a Button and the button content is binded to a custom class
I have created a custom Button class and I want to be able to
I have a custom button, subclassed from UIButton that is initialised as below (obviously
I have a custom button class called ImageButton that extends JButton. In it i
In my button.xul file I have this: <script type=application/x-javascript src=chrome://mf_unblocker/content/button.js/> <toolbarbutton id=custom-button-1 label=Custom tooltiptext=MAFIAAFire:
I have the following problem / bug: I made a custom button-class (called CustomBlitButton)
I have a background MovieClip in a custom button class, which moves the play
I have a custom button which inherits from UIButton. I'm handling the TouchUpInside event
I have a CustomButton class (extends LinearLayout ) where I inflate a layout which

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.