简体   繁体   中英

IOS toolbar not showing

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

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 UIBarButtonItem s.

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 .

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 toolbar 默认情况下,大小检查器将显示为这样 3) Remove bottom vertical line and select top one. 正确的自动调整大小选项如下所示

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM