【问题标题】:IOS - toolbar is not appearing on topIOS - 工具栏没有出现在顶部
【发布时间】:2014-03-16 04:43:25
【问题描述】:

我也问过这个问题here,但我没有得到任何解决方案。所以我再次在这里询问完整的解释。

我从here 下载了 EPub Reader 库。当我运行这个库时,首先出现一个表格视图,其中包含四行,其值为 EPUB、PDF 等,然后单击“EPUB”行 book 成功出现在顶部工具栏上。因为我必须在开始时首先加载这本书而不是显示工具栏,所以我对代码做了一些更改。从 didSelectRowAtIndexPath 复制一些代码并将该代码添加到 delegate.m 中。所以现在的问题是书籍已成功加载,但工具栏未显示

这是我的代码

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

加载epubView的代码在原库的RootViewController.m中

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

这是我对 EpubViewController 的 didLoadMethod 的看法

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

这是图片

我想再说一遍,当我从Case 2 显示 epubViewController 时,工具栏可以正常工作,我的意思是如果我必须先显示表格视图,请单击该行。

【问题讨论】:

    标签: ios iphone objective-c uinavigationitem epub


    【解决方案1】:

    您的工具栏隐藏为导航栏,因为导航栏始终位于顶部您可以将您的工具栏添加为导航栏的子视图我不确定它是否会工作,尽管最好的方法是使用导航栏并添加它喜欢的项目左键右键和标题的东西,或者你可以添加一个视图作为导航栏的子视图,我在示例代码之前已经这样做了

    navBar=self.navigationController.navigationBar;
    
    
        [navBar addSubview:statusBar];
        statusBar.frame=f;
    
        self.navigationController.navigationBar.translucent = YES;
    

    这里的 statusBar 是一个视图,设置的大小与您的工具栏相同。

    【讨论】:

    • 没问题,但请确保如果您进入下一页,请隐藏此视图,因为它将在每个页面上保持相同。如果您需要任何进一步的帮助,联系我会很棘手
    • 谢谢,但我没听懂。为什么我必须隐藏工具栏?我将如何联系您?你能给我你的 Skype 或电子邮件吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 2015-01-29
    相关资源
    最近更新 更多