OGeek|极客世界-中国程序员成长平台

标题: iOS从导航 Controller 子类设置工具栏项目 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 03:32
标题: iOS从导航 Controller 子类设置工具栏项目

我已将我的 UINavigationController 子类化并尝试设置工具栏项,但它们没有出现。我已经在 Storyboard中为导航 Controller 设置了类。在 View Controller 中,我在 viewDidAppear 方法中设置了 [self.navigationController setToolBarHidden:NO animated:NO]。下面是我在子类中使用的代码。任何帮助都会非常感谢。

@interface FCMapNavigationController ()

@end

@implementation FCMapNavigationController

- (void)viewDidLoad
{
    // Call super
    [super viewDidLoad];

    NSLog(@"Toolbar = %@", self.toolbar);

    // Set the toolbar items
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems[@"Standard", @"Satellite", @"Hybrid", @"Terrain"]];
    //[segment addTarget:self actionselector(changeMapType forControlEvents:UIControlEventValueChanged];
    //[segment setSelectedSegmentIndex:self.mapView.mapType - 1];
    UIBarButtonItem *seg = [[UIBarButtonItem alloc] initWithCustomView:segment];
    UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    //self.refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self actionselector(refreshData)];
    [self setToolbarItems[flex, seg, flex]];
}

@end



Best Answer-推荐答案


唯一的 UIViewController 可以影响工具栏项。所以你可以这样解决:

class NavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.topViewController.setToolbarItems([/*your items*/], animated: false)
    }

}

关于iOS从导航 Controller 子类设置工具栏项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27002972/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4