iOS工具栏不显示 [英] IOS toolbar not showing

查看:66
本文介绍了iOS工具栏不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ios编程的新手.我遇到的问题是我已经在我的xib文件中设置了一个工具栏,但是运行该应用程序后,该工具栏不显示.我在viewDidLoad函数和delegant.m类中都添加了此行,但工具栏仍未显示

i am new to ios programming. the problem i am having is i have set a toolbar in my xib file but after running the app the toolbar dont show. i have added this below line both in viewDidLoad function and in delegate.m class but still toolbar not showing

self.navigationController.toolbarHidden = NO;

这是我的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [userDefaults objectForKey:@"AppleLanguages"];

    EPubViewController *epubView = [[EPubViewController alloc] init];
    [epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"AtoZbook" ofType:@"epub"]]];
    self.navigationController = [[UINavigationController alloc]initWithRootViewController:epubView];
    self.navigationController.toolbarHidden = NO;

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

EPubViewController.m

EPubViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

     self.navigationController.toolbarHidden = NO;


    loadingIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    loadingIndicator.center = CGPointMake(toolbar.frame.size.width/2 ,toolbar.frame.size.height/2);
    [loadingIndicator startAnimating];
    toolbar.alpha = 0.8;
    [self.toolbar addSubview:loadingIndicator];


    [webView setDelegate:self];

    UIScrollView* sv = nil;
    for (UIView* v in  webView.subviews) {
        if([v isKindOfClass:[UIScrollView class]]){
            sv = (UIScrollView*) v;
            sv.scrollEnabled = NO;
            sv.bounces = NO;
        }
    }
    currentTextSize = 100;

    //Webview
    UISwipeGestureRecognizer* rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoNextPage)] ;
    [rightSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];

    UISwipeGestureRecognizer* leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoPrevPage)] ;
    [leftSwipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];


    [webView addGestureRecognizer:rightSwipeRecognizer];
    [webView addGestureRecognizer:leftSwipeRecognizer];

    [self performSelector:@selector(stratRolling)];
}

推荐答案

一个 UINavigationController 已经包含一个工具栏,您无需自己创建一个工具栏.如果您在模拟指标"设置下添加了一个,则仅用于显示,实际上并未在视图层次结构中添加工具栏.

A UINavigationController already contains a toolbar and you shouldn't need to create one yourself. If you added one under the "Simulated Metrics" setting this is only for show and doesn't actually add a toolbar to the view hierarchy.

除了使用语句 self.navigationController.toolbarHidden = NO; ,您还需要在 viewDidLoad 中调用 [self setToolbarItems:items] >对于 EPubViewController ,其中 items 是包含 UIBarButtonItem s的 NSArray .

Apart from having the statement self.navigationController.toolbarHidden = NO; you will also need to call [self setToolbarItems:items] in viewDidLoad for EPubViewController, where items is an NSArray containing UIBarButtonItems.

如果您的想法是最初只在工具栏上使用微调器,则可能需要查看

If your idea is to initially only have a spinner in the toolbar you might want to look into the - (id)initWithCustomView:(UIView *)customView constructor of UIBarButtonItem.

这篇关于iOS工具栏不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆