我已经将我的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
答案 0 :(得分: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)
}
}