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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:49:51+00:00 2026-06-12T08:49:51+00:00

I have the following view controller structure in my app: A container view controller

  • 0

I have the following view controller structure in my app:

A container view controller with a UIToolBar (which is not a navigation bar) has a UIPageViewController embedded and this UIPageViewController presents additional child view controllers:

container view controller (toolBar) -> PageViewController -> ViewController 1,
                                                             ViewController 2

I would like to add and remove buttons (BarButtonItems) to and from the toolbar on the container view controller depending on the child view controllers 1 and 2 presented.

  1. How would you recommend that the child view controllers 1 and 2
    access the toolbar in the container view controller to add and
    remove buttons?

  2. It seems that the toolbarItems property in the container view
    controller is always 0 even though there are buttons in it. Any
    ideas on why this could be? Is the toolbarItems property <> 0
    only for navigation bars?

Edit

Based on the suggestion from user DBD I have added the following methods to the view controller CompanyViewController which has the toolbar and is the base class for my view controllers in a split views detail window (all my detail view controller inherit from CompanyViewController). One of these detail view controllers is used as a content view controller with a page view controller and the child view controllers described above.

CompanyViewController:

- (void)addToolBarItems:(NSArray *)buttonArray
{
    NSMutableArray *items = [[self.toolbar items] mutableCopy];
    
    [buttonArray enumerateObjectsUsingBlock:^(UIBarButtonItem *barButtonItem, NSUInteger idx, BOOL *stop) {
        if (! [items containsObject:barButtonItem] ) [items insertObject:barButtonItem atIndex:0];
    }];
    [self.toolbar setItems:items animated:NO];
}

- (void)removeToolBarItems:(NSArray *)buttonArray;
{
    NSMutableArray *items = [[self.toolbar items] mutableCopy];
    
    [buttonArray enumerateObjectsUsingBlock:^(UIBarButtonItem *barButtonItem, NSUInteger idx, BOOL *stop) {
        if ( [items containsObject:barButtonItem] ) [items removeObjectAtIndex:idx];
    }];
    [self.toolbar setItems:items animated:NO];
}

This is how I try to access the CompanyViewController from my child controllers:

- (CompanyViewController*)parentViewControllerWithToolbar
{
    UIViewController *parentPageViewController = self.parentViewController;
    CompanyViewController *parentContentViewController = (CompanyViewController*)parentPageViewController.parentViewController;
    return (CompanyViewController*)parentContentViewController;
}

However, when trying to call the addToolBarItems method from the child view controller I can’t get the method in Xcodes’s autocomplete: It seems that I have no access to this method even though I imported #import "CompanyViewController.h".

Any suggestions on what I might be missing here?

  • 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-12T08:49:52+00:00Added an answer on June 12, 2026 at 8:49 am

    I would suggest not accessing the toolbar directly. Instead, I’d suggest the container class having public methods like

    - (void)addToolBarItem:(UIBarButtonItem *)button atIndex:(int)index;
    - (void)removeToolBarItemAtIndex:(int)index;
    

    Then all your child has to do is get the parent, possibly do a type cast and call the method.

    Encapsulating your UI changes like this remove the need for potentially duplicate code in your child classes to modify the toolbar, protect much of your code from possible API changes by Apple and allow you to easily decide to swap out the tool bar to something like a custom control in the future without causing ripple code change effects.

    EDIT:

    I thought you were using a container view controller, not a UISplitViewController. I’m going to re-state my understanding so you can tell me if I got it wrong.

    You have a UISplitViewController displaying a “master” and “detail” views. You want the detail view to call back to the master and request a toolbar change.

    In detail view controller, you want the master, but calling “parent” just gives you the UISplitViewController. So you have to access the split view controller and get the master view controller from there.

    MasterViewController *foo = [self.splitViewController.viewControllers objectAtIndex:0];
    [foo removeToolBarItems:bar];
    

    Which says, go get the UISplitViewController which I belong to (same as calling parent), then access the array of view controllers it holds. Take the first item in the array and assign as your master view controller. From the docs on the UISplitViewController

    viewControllers
    The array of view controllers managed by the receiver.

    @property(nonatomic, copy) NSArray *viewControllers

    Discussion
    The
    array in this property must contain exactly two view controllers. The
    view controllers are presented left-to-right in the split view
    interface when it is in a landscape orientation. Thus, the view
    controller at index 0 is displayed on the left side and the view
    controller at index 1 is displayed on the right side of the interface

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

Sidebar

Related Questions

I have the following view controller in my UIPopover: @protocol StorePopoverDelegate - (void)storeSelected:(NSString *)store;
I have the following View, Controller and Comment.cs code, but I get an error,
I have the following model, view and controller. Model public class Person { public
I have the following ActionLink in my view <%= Html.ActionLink(LinkText, Action, Controller); %> and
If i have a controller action Create that returns a view with the following
I have a view controller, which creates 2 view controllers inside it. Inside each
I have the following link structure for my portfolio: <?php echo $this->Html->link($post['Portfolio']['title'], array('controller' =>
I have a navigation problem. I want to create the following navigation structure: Start
I have the following environment: root view controller is UINavigationController a number of custom
I have following view <asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <h2>Tables <%=ViewData[RetriverName] %></h2> <%using (Html.BeginForm(ResfreshSelectedTables, Home))

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.