【问题标题】:iOS set toolbar items from nav controller subclassiOS从导航控制器子类设置工具栏项目
【发布时间】:2015-01-16 03:39:25
【问题描述】:

我已将我的 UINavigationController 子类化并尝试设置工具栏项,但它们没有出现。我已经在故事板中为导航控制器设置了类。在视图控制器中,我在 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 action:@selector(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 action:@selector(refreshData)];
    [self setToolbarItems:@[flex, seg, flex]];
}

@end

【问题讨论】:

    标签: ios uinavigationcontroller subclass toolbar uitoolbar


    【解决方案1】:

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

    class NavigationController: UINavigationController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
            self.topViewController.setToolbarItems([/*your items*/], animated: false)
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多