iphone - UIPageViewController 的 NavigationBar 不显示标题

标签 iphone ios objective-c uinavigationbar

UIPageViewController 的导航栏不显示页码作为导航栏的标题。

- (void)viewDidLoad {

[super viewDidLoad];

//modelArray holds the page numbers
modelArray = [[NSMutableArray alloc] init];

for (int index = 1; index <= totalPages; index++) {

    [modelArray addObject:[NSString stringWithFormat:@"%i", index]];

}

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 45)];

navBar.tintColor = [UIColor colorWithRed:243.0/255.0 green:164.0/255.0 blue:0.0/255.0 alpha:1.0];

self.navigationItem.title = modelArray;

[self displayPageNumber:1];

thePageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal options:nil];

thePageViewController.delegate = self;
thePageViewController.dataSource = self;

thePageViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

contentViewController = [[ContentViewController alloc] initWithPDF:PDFDocument];
contentViewController.page = [modelArray objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:contentViewController];
[thePageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:thePageViewController];
[self.view addSubview:thePageViewController.view];
thePageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);


[thePageViewController didMoveToParentViewController:self];

_toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 960, self.view.bounds.size.width, 45)];

_toolbar.barStyle = UIBarStyleBlackOpaque;

_toolbar.tintColor = [UIColor colorWithRed:243.0/255.0 green:164.0/255.0 blue:0.0/255.0 alpha:1.0];

 [self.view addSubview:_toolbar];

[self.view addSubview:navBar];
 }

  - (void) pageViewController:(PageViewController *)pageViewController willTurnToPageAtIndex:(NSUInteger)pageIndex {
[self displayPageNumber:pageIndex + 1];
}


   - (void) displayPageNumber:(NSUInteger)pageNumber {
self.navigationItem.title = [NSString stringWithFormat:
                             @"Page %u of %u",
                             pageNumber,
                             CGPDFDocumentGetNumberOfPages(PDFDocument)];
     }

感谢您的帮助。

最佳答案

很简单。

这样做

_navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 45)];

_navBar.tintColor = [UIColor colorWithRed:243.0/255.0 green:164.0/255.0 blue:0.0/255.0 alpha:1.0];

UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:[NSString stringWithFormat:
                                                                   @"Page %i of %i",
                                                                   pageNumber,
                                                                   CGPDFDocumentGetNumberOfPages(thePDF)]];
[_navBar pushNavigationItem:title animated:NO];

希望对你有帮助。

关于iphone - UIPageViewController 的 NavigationBar 不显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429101/

相关文章:

ios - 更改文本字段和 "save before quit"

iphone - 在 iPhone 中返回上一个屏幕

iphone - 关于cocoa框架中使用kvo时释放对象

iphone - 将基于自定义 View 的 UIBarButtonItem 放置在没有默认水平填充的导航栏中

iphone - 在iPad上创建有关用户事件的日志的最佳方法

ios - watchOS 7 不再更新并发症

ios - 在 iONIC Cordova iOS 中预填充 SQLite 数据库

ios - 当联系人具有 LinkedContacts 时,ABMultiValueGetIndexForIdentifier 返回不正确的索引

iphone - 如何在 iOS 应用程序中实现互斥量

ios - 显示多个 map 的 SKMaps