IOS toolbar not showing

2019-08-29 05:52发布

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;

here is my code

- (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

- (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)];
}

2条回答
Fickle 薄情
2楼-- · 2019-08-29 06:17

The issue seems to be in your xib file. Please check if any auto resizing is set for toolbar? Usually it should be selected on top and unselected on bottom. 1) Go to the XIB. 2) Select toolbarBy Default Size inspector will show it like this 3) Remove bottom vertical line and select top one. Correct Autoresizing option looks like this

Hope this helps.

查看更多
姐就是有狂的资本
3楼-- · 2019-08-29 06:20

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.

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.

查看更多
登录 后发表回答