IOS - 工具栏没有出现在顶部

时间:2014-03-16 04:43:26

标签: ios iphone objective-c uinavigationitem epub

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

我从here下载了EPub阅读器库。当我运行这个库时,首先出现一个表视图,其中包含四行,其值为EPUB,PDF等,并在单击“EPUB”行后 使用顶部工具栏成功显示书籍。因为我必须首先加载本书而不是显示工具栏,我对代码进行了一些更改。从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)];
}

这是图像

enter image description here enter image description here

我想再次说明,当我从Case 2显示epubViewController时,如果我必须首先显示表格视图,则单击该行,工具栏正常工作。

1 个答案:

答案 0 :(得分:0)

你的工具栏隐藏了导航栏,因为导航栏总是在顶部你可以添加你的工具栏作为导航栏的子视图我不知道它是否会工作虽然最好的approch是使用导航栏并添加项目就像它左键按钮右键和标题内容,或者您​​可以添加视图作为导航栏的子视图我在示例代码之前已经完成了

navBar=self.navigationController.navigationBar;


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

    self.navigationController.navigationBar.translucent = YES;

这里statusBar是一个视图设置,就像你的工具栏一样大小。