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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:01:29+00:00 2026-06-16T14:01:29+00:00

I am trying to subclass UIBarButtonItem to add some special functionality. I need the

  • 0

I am trying to subclass UIBarButtonItem to add some special functionality. I need the barButtonItem to toggle its appearance when touched, and am therefore attempting to override performSelector:.

When I use the code below, I get an EXC_BAD_ACCESS (code=2 ...)

-(id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2
{
    // Do something

    return [super performSelector:aSelector withObject:object1 withObject:object2];
}

My guess is that I am either wrongly attempting to override performSelector: (is there another way?) or incorrectly calling the method on super.

After searching for a solution for 3+ hours I have found nothing. Any help is greatly appreciated.

Update:
The following works:

@implementation CustomBarButtonItem

- (void)setTarget:(id)target
{
    _realTarget = target;
    super.target = self;
}

- (void)setAction:(SEL)action
{
    _realAction = action;
    super.action = @selector(pressed);
}

- (void)pressed
{
    [self doCustom]; // implement this somewhere
    [_realTarget performSelector:_realAction withObject:nil afterDelay:0];
}

Unfortunately I wanted to toggle between having a customView and the normal UIBarButtonItem look by setting self.customView = nil which only works sometimes. But that is a-whole-nother question. Thanks all.

I will wait a little longer to choose a best answer to see if there are better solutions.

  • 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-16T14:01:30+00:00Added an answer on June 16, 2026 at 2:01 pm

    Probably better to implement this functionality using a simple UIView that you can simply modify in any given way.

    UIBarButtonItem does provide a way for initializing based on a custom UIView:

    - (id)initWithCustomView:(UIView *)customView

    You could then tell the UIView to change its appearance based on the touch events fired by the UIBarButtonItem.

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

Sidebar

Related Questions

I'm trying to subclass UIImageView to add some custom functionality in it. I started
I'm trying to subclass the built-in file class in Python to add some extra
I'm trying to subclass str , but having some difficulties due to its immutability.
I am trying to subclass System.Windows.Controls.DataGrid in order to add special commands to which
I'm trying to subclass Array in ruby to make it randomize its elements when
I am trying to subclass CCSprite but for some reason I can't seem to
I am trying to programmatically create a UIViewController subclass whose view includes some buttons,
I'm trying to have a custom subclass of NSTableView observe the value of its
I'm trying to add a subclass of View to my activity_main.xml like this .
I am trying to add attributes to a subclass of pandas.DataFrame and they disappear

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.