简体   繁体   中英

IOS - toolbar is not appearing on top

i have asked this question here also but i didn't get any solution.so i am asking here again with the full explanation.

I downloaded EPub Reader library from here . When i run this library,first comes a table view which contain four rows having values EPUB ,PDF etc and after clicking on the "EPUB" row book appears successfully with the top toolbar. Because i have to load the book first in start instead of showing the toolbar i did some changes with the code. copied some code from didSelectRowAtIndexPath and added that code into delegate.m. so now the problem is book is successfully loading but the toolbar is not showing up

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.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

the code of loading epubView was in RootViewController.m in the original library

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    switch (indexPath.row) {
        //TXT
        case 0:{
           //txt

        }
            break;
        //PDF
        case 1:{
             //PDF
        }
            break;
        //EPUB
        case 2:{
            epubView = [[EPubViewController alloc] init];
            [epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"The Chessmen of Mars" ofType:@"epub"]]];
            epubView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            [self presentModalViewController:epubView animated:YES];
            [epubView release];
        }
            break;
        case 3:{
           //another book
        }
            break;

        default:
            break;
    }


}

here is my view didLoadMethod of EpubViewController

- (void)viewDidLoad {
    [super viewDidLoad];




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

here are the images

在此处输入图片说明在此处输入图片说明

i want to say again that the toolbar works fine when i show the epubViewController from the Case 2 i mean by clicking the row if i have to show the table view first.

your tool bar is hiding being navigation bar since navigation bar is always on top you can add your tool bar as sub view of navigation bar im not sure if it will work though best approch is use navigation bar and add item it it like left button right button and title stuff or you can add a view as subview of navigation bar i have done that before sample code

navBar=self.navigationController.navigationBar;


    [navBar addSubview:statusBar];
    statusBar.frame=f;

    self.navigationController.navigationBar.translucent = YES;

here statusBar was a view was set up like your tool bar same size.

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