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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:24:04+00:00 2026-06-08T22:24:04+00:00

I have a UIBarButtonItem *button. The idea is that the user presses the button

  • 0

I have a UIBarButtonItem *button. The idea is that the user presses the button and then a window pops out. This is declared in the target/action of the button (i.e. tapping the button calls

(void)showMyWindow:(id)sender

where the sender is the UIBarButtonItem.

In the showMyWindow: method, the drawing of the pop-up window requires the frame of the sender. Now, UIBarButtonItem doesn’t typically allow you to access its frame. As a bit of a hack, I’ve cast the sender to a UIView and then accessed this UIView’s frame. I didn’t think this would work but, surprisingly, it does.

However, I also want to call the showMyWindow: method elsewhere. So I have this line of code:

[self performSelector:@selector(showMyWindow:) withObject:self.button];

Here, my app crashes. I’ve pinpointed the problem exactly to this:

(void)showMyWindow:(id)sender 
{
    //I should be checking before the cast here, but it helps illustrate the problem
    UIView *senderAsView = (UIView *)sender
    CGRect frame = senderAsView.frame;
    ...
}

The point is: I can somehow perform this cast+access the frame when I call the method with target-action, but not when I use performSelector:withObject:

Why is there a difference? Why can this cast be performed in one case but not the other?

Thanks.

  • 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-08T22:24:05+00:00Added an answer on June 8, 2026 at 10:24 pm

    As a bit of a hack, I’ve cast the sender to a UIView and then accessed this UIView’s frame. I didn’t think this would work but, surprisingly, it does.

    UIBarButtonItem is descended from NSObject, not UIView, and does not have a frame property. The sender in this case is most likely not your bar button item, but either a private view belonging to it (if you are using a system item) or the custom view property of it.

    When you call it “manually” you really are sending the UIBarButtonItem instance, which does not have a frame, and will crash when you cast it to a UIView and ask it for the frame property.

    You can clarify what is really being sent by examining the sender object in the debugger. It will be a view subclass in the first instance, and a UIBarButtonItem (or subclass) in the second.

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

Sidebar

Related Questions

I have this code: UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:textField action:@selector(setText:)]; How do
I have a toolbar button UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(pressButton2:)]; systemItem2.style
I have the following code: UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showAddNewView)]; -
I have created my own leftBarButtonItem: UIBarButtonItem* homeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(homeButtonClicked:)];
I have created button for home like this: UIBarButtonItem * addButton=[[UIBarButtonItem alloc] initWithTitle:@Home style:UIBarButtonItemStyleBordered
Up in viewDidLoad I have: UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; For
I have this code that changes the back button of my UINavigationBar // Set
I have a UIBarButtonItem containing a button, on which I've set custom background images
I have a UIToolbar. If I create a UIBarButton like this, it works: UIBarButtonItem
I have a UIPopoverController presented from a UIBarButtonItem. I have another UIBarButtonItem that is

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.