0

My setup

In a main storyboard i'm using a SWRevealViewController for a sidebar with links to different sections.

Each section is represented in a separated storyboard linked in the main storyboard with RBStoryboardLink.

If in the child storyboards i perform segues to scenes the main navigation controller it's able to represents this putting the destination scene title and a back button. At this point all works well.

An aproximation to the schema is:

-SWRevealViewController
 |-> (SWRevealViewControllerSegue) -> sw_front
 |-> (SWRevealViewControllerSegue) -> sw_rear

-(sw_rear)UITableViewController
 |(each row selection)
 |-> SWRevealViewControllerSegue -> (CommonContainer)

-CommonContainer
 |-> Container -> Embed segue for container -> RBStoryboardLink

- RBStoryboardLink
 |->(User defined runtime attributes) "storyboardName" : "target_storyboard"

-SpecfificControllerOfTargetedStoryboard
 -(void)viewDidLoad{
    UIBarButtonItem * button = //...
    self.topViewController.navigationItem.rightBarButtonItem = button;//DOESN'T WORK

My problem

I can't add rightBarButtonItems to the main navigation bar from the child storyboards.

What i have tried but without success

Dynamically add barbuttons using singleton

I had made the main navigationcontroller a singleton with a method for add a button passed from the child scenes of the differents storyboards.

- (void) addRightButton:(UIBarButtonItem *) button{
    self.topViewController.navigationItem.rightBarButtonItem = button;
}

This only works at the first time, even when on the menu the root scene is called.

Narrow the main navigationbar

The worst solution, also don't work. I'm not able to change the main navigationbar width in order to reveal the child scenes top buttons.

BuguiBu
  • 1,507
  • 1
  • 13
  • 18

1 Answers1

0

I've solved my problem in this no elegant way:

In the CommonContainer or specific container i've added the nagivation items desired, and associate a IBAction target that send a message received by the specific UIViewControllers of the desired storyboard.

-CommonContainer
 |-> Container -> Embed segue for container -> RBStoryboardLink
 |-(void)viewDidLoad{
     UIButton *rightButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 15, 13)];
     [rightButton setBackgroundImage:[UIImage imageNamed:@"mv-white-setting.png"] forState:UIControlStateNormal];
     [rightButton setTitle:@"" forState:UIControlStateNormal];
     [rightButton addTarget:self action:@selector(rightTopBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
     UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
     self.navigationController.topViewController.navigationItem.rightBarButtonItem = rightButtonItem;
 }
 |- (IBAction)rightTopBarButtonAction:(id)sender {
     [[NSNotificationCenter defaultCenter] postNotificationName:@"movements_rightTopBarButtonAction" object:nil];
 }

- RBStoryboardLink
 |->(User defined runtime attributes) "storyboardName" : "target_storyboard"

-SpecfificControllerOfTargetedStoryboard
 |-(void)viewDidLoad{
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rightButtonAction:) name:@"movements_rightTopBarButtonAction" object:nil];
BuguiBu
  • 1,507
  • 1
  • 13
  • 18