无法设置UITabBarController的moreNavigationController的右键

时间:2011-03-16 13:15:23

标签: iphone objective-c ios

我有一个非常奇怪的问题,我可以设置UITabBarController的moreNavigationController的所有属性,除了rightBarButtonItem属性。我猜这可能是因为与customizableViewControllers属性相关的一些错误禁用了所有正确的栏按钮项。任何想法如何解决?

    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] 
                                   initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                                   target:self 
                                   action:@selector(popViewController)];

    self.customizableViewControllers = nil;
    self.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.moreNavigationController.topViewController.navigationItem.title = @"test"; //this works
    self.moreNavigationController.topViewController.navigationItem.leftBarButtonItem = doneButton; // this works
    self.moreNavigationController.topViewController.navigationItem.rightBarButtonItem = doneButton; // this doesn't

2 个答案:

答案 0 :(得分:5)

好的解决方案是使用moreNavigationController的委托

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *) viewController animated:(BOOL)animated {

viewController.navigationItem.rightBarButtonItem = doneButton;

}

答案 1 :(得分:0)

Paludis,非常感谢!这是现在的修复。

 func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
        //More navigation controller Bug. The rightBarButton item disappears on pop, in case this is MoreNavControl
        navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "createProject")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        if (self.navigationController == self.tabBarController?.moreNavigationController)
        {
            self.navigationController?.delegate = self
        }
        else
        {
            navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "createProject")
        }
}