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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:43:59+00:00 2026-06-08T10:43:59+00:00

I have a class RootViewController where I have a UIBarButtonItem declared. The method to

  • 0

I have a class RootViewController where I have a UIBarButtonItem declared. The method to display it is in another class FirstDetailViewController.

I am trying to access it in another class SecondDetailViewController, but it is always null. I tested with some other variables and they were null as well. Here’s what I have:

RootViewController.h

@interface RootViewController : UITableViewController <UISplitViewControllerDelegate> {

}

@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;
...
@end

RootViewController.m

#import "RootViewController.h"
#import "FirstDetailViewController.h"

@implementation RootViewController

@synthesize popoverController, splitViewController, rootPopoverButtonItem;

- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc {

    NSLog(@"splitviewController will hide");

    // Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.
    barButtonItem.title = @"Menu";
    self.popoverController = pc;
    self.rootPopoverButtonItem = barButtonItem;
    UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
    [detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}

FirstDetailViewController.m

- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {

    NSLog(@"show root popover button item");

    // Add the popover button to the toolbar.
    NSMutableArray *itemsArray = [toolbar.items mutableCopy];
    [itemsArray insertObject:barButtonItem atIndex:0];
    [toolbar setItems:itemsArray animated:NO];
    [itemsArray release];
}

SecondDetailViewController.h

    #import "RootViewController.h"

    @class RootViewController;

    @interface SecondDetailViewController : UIViewController <SubstitutableDetailViewController, UIScrollViewDelegate, UITextFieldDelegate, UITextViewDelegate> {
    ...
    }
    @property (nonatomic, retain) RootViewController *root;
    @end

SecondDetailViewController.m

#import "SecondDetailViewController.h"

@implementation SecondDetailViewController

@synthesize root;

...
NSLog(@"view class : %@", [root.splitViewController class]);
[detailViewController showRootPopoverButtonItem:root.rootPopoverButtonItem];
...
  • 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-08T10:44:02+00:00Added an answer on June 8, 2026 at 10:44 am

    You probably aren’t setting the “root” property of SecondDetailViewController to the instance of RootViewController that you want to access the UIBarButtonItem for. Then you’re reading an uninitialized instance of RootViewController in your SecondDetailViewController code, and the only reason you don’t get an error is that Objective C silently ignores calls to methods on nil objects (in this case the rootPopoverButtonItem getter method, which the root.rootPopoverButtonItem is shorthand for).

    If your instance of “RootViewController” is called “myRootViewController”, then somewhere in your code you have to do something like:

    SecondDetailViewController *mySecondDetailViewController = [[SecondDetailViewController alloc] init];
    mySecondDetailViewController.root = myRootViewController;
    

    Then you’ll be accessing the copy of RootViewController that has the bar button you want.

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

Sidebar

Related Questions

I have Class and Student objects. Both have collection of another as property. Which
We have class lua. In lua class there is a method registerFunc() which is
The issue: I have a UINavigationController as as subview of UIWindow, a rootViewController class
I'm trying to develop a basic GPA Calculator. I have an AllCourses class that
i have class like this DrillDownAppAppDelegate.h PictureCell.h RootViewController.h SlideShowViewController.h DrillDownAppAppDelegate.m PictureCell.m RootViewController.m SlideShowViewController.m i
I have overridden the tableView:indentationLevelForRowAtIndexPath method in my UITableViewController derived class as follows: -
I have a RootViewController class and a UserSettingsController class. I have defined the UITableView
I have a table view class called RootViewController and a class providing WiFi functionality
I have a navigation controller app. I created a RootViewController class with Xib file.
I need to show another view from rootviewcontroller on button click. I have written

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.