我是ios编程的新手。我遇到的问题是我在我的xib文件中设置了一个工具栏但在运行应用程序后工具栏不显示。我已经在viewDidLoad函数和delegate.m类中添加了以下行,但仍然没有显示工具栏
self.navigationController.toolbarHidden = NO;
这是我的代码
- (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)];
}
答案 0 :(得分:0)
UINavigationController
已经包含工具栏,您不需要自己创建一个工具栏。如果您在“模拟指标”设置下添加了一个,则仅用于显示,并且实际上不会将工具栏添加到视图层次结构中。
除了声明self.navigationController.toolbarHidden = NO;
之外,您还需要在[self setToolbarItems:items]
中为viewDidLoad
致电EPubViewController
,其中items
为NSArray
包含UIBarButtonItem
s。
如果您的想法最初只是在工具栏中有一个微调器,您可能需要查看UIBarButtonItem
的{{3}}构造函数。
答案 1 :(得分:-3)
问题似乎出现在您的xib文件中。请检查是否为工具栏设置了自动调整大小? 通常它应该在顶部选择,在底部未选中。 1)转到XIB。 2)选择工具栏 3)移除底部垂直线并选择顶部垂直线。
希望这有帮助。