我已将我的 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
唯一的 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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |