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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:32:00+00:00 2026-05-30T19:32:00+00:00

I have a UIBarButtonItem with UIButton as custom view. The UIButton has a addTarget:action:

  • 0

I have a UIBarButtonItem with UIButton as custom view.

The UIButton has a addTarget:action: on it. In the action I present a popover. I’m currently presenting from the sender.frame (the UIButton‘s Frame) I want to Present from the UIBarButtonItem instead.

How can I access the UIBarButtonItem from the UIButton?

  • 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-30T19:32:01+00:00Added an answer on May 30, 2026 at 7:32 pm

    If you have set your UIButton as the customView of a UIBarButtonItem, or a child of the custom view, then you can walk up the view hierarchy from your button until you find the UIToolbar or UINavigationBar that contains the button, then search the bar’s items for the one whose custom view is the button (or an ancestor of the button).

    Here’s my completely untested code for doing that. You would call [[self class] barButtonItemForView:myButton] to get the item containing your button.

    + (BOOL)ifBarButtonItem:(UIBarButtonItem *)item containsView:(UIView *)view storeItem:(UIBarButtonItem **)outItem {
        UIView *customView = item.customView;
        if (customView && [view isDescendantOfView:customView]) {
            *outItem = item;
            return YES;
        } else {
            return NO;
        }
    }
    
    + (BOOL)searchBarButtonItems:(NSArray *)items forView:(UIView *)view storeItem:(UIBarButtonItem **)outItem {
        for (UIBarButtonItem *item in items) {
            if ([self ifBarButtonItem:item containsView:view storeItem:outItem])
                return YES;
        }
        return NO;
    }
    
    + (UIBarButtonItem *)barButtonItemForView:(UIView *)view {
        id bar = view;
        while (bar && !([bar isKindOfClass:[UIToolbar class]] || [bar isKindOfClass:[UINavigationBar class]])) {
            bar = [bar superview];
        }
        if (!bar)
            return nil;
    
        UIBarButtonItem *item = nil;
    
        if ([bar isKindOfClass:[UIToolbar class]]) {
            [self searchBarButtonItems:[bar items] forView:view storeItem:&item];
        }
    
        else {
            UINavigationItem *navItem = [bar topItem];
            if (!navItem)
                return nil;
            [self ifBarButtonItem:navItem.backBarButtonItem containsView:view storeItem:&item]
            || [self ifBarButtonItem:navItem.leftBarButtonItem containsView:view storeItem:&item]
            || [self ifBarButtonItem:navItem.rightBarButtonItem containsView:view storeItem:&item]
            || ([navItem respondsToSelector:@selector(leftBarButtonItems)]
                && [self searchBarButtonItems:[(id)navItem leftBarButtonItems] forView:view storeItem:&item])
            || ([navItem respondsToSelector:@selector(rightBarButtonItems)]
                && [self searchBarButtonItems:[(id)navItem rightBarButtonItems] forView:view storeItem:&item]);
        }
    
        return item;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIBarButtonItem with a custom view of a UIbutton with an image,
I have a custom UIButton as follows: UIButton * action = [UIButton buttonWithType:UIButtonTypeCustom]; [action
I have a UIBarButtonItem containing a button, on which I've set custom background images
I have a refresh button on my navigationbar buttonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(buttonItemClicked)];
I have a UIBarButtonItem that has a UITextField as its customView. The toolbar contains
I have 3 view controllers (VCs) A B C. Firstly i present A. Then
I have a UIBarButtonItem opening an action sheet to offer users choices about what
I have an iPhone app which has a tabBarController as the root view controller
I have a UIButton that pushes to another view controller using the following code.
I Have a UIButton and it has multiple actions associated with it To play

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.