0

我的设置

在主情节提要中,我使用SWRevealViewController作为侧边栏,其中包含指向不同部分的链接。

每个部分都表示在一个单独的故事板中,该故事板在主故事板中使用RBStoryboardLink 链接

如果在子情节提要中,我对主导航控制器的场景执行 segues,则它能够表示这放置目标场景标题和后退按钮。在这一点上,一切正常。

模式的近似值是:

-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

我的问题

我无法从子故事板将 rightBarButtonItems 添加到主导航栏。

我尝试过但没有成功

使用单例动态添加条形按钮

我已经使主导航控制器成为一个单例,并使用一种方法来添加从不同故事板的子场景传递的按钮。

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

这仅在第一次有效,即使在菜单上调用根场景时也是如此。

缩小主导航栏

最糟糕的解决方案,也不起作用。我无法更改主导航栏宽度以显示子场景顶部按钮。

4

1 回答 1

0

我以这种不优雅的方式解决了我的问题:

在 CommonContainer 或特定容器中,我添加了所需的导航项,并关联了一个 IBAction 目标,该目标发送由所需故事板的特定 UIViewControllers 接收的消息。

-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];
于 2014-06-24T11:43:24.173 回答