0
我所做的一切都是當用戶翻頁時更新導航欄。以下是我的代碼更新導航欄
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController {
contentViewController = [[ContentViewController alloc] initWithPDF:PDFDocument];
currentIndex = [modelArray indexOfObject:[(ContentViewController *)viewController page]];
if (currentIndex == 0) {
return nil;
}
contentViewController.page = [modelArray objectAtIndex:currentIndex - 1];
[self updateNavigationBar];
return contentViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController {
contentViewController = [[ContentViewController alloc] initWithPDF:PDFDocument];
//get the current page
currentIndex = [modelArray indexOfObject:[(ContentViewController *)viewController page]];
if (currentIndex == totalPages - 1) {
return nil;
}
contentViewController.page = [modelArray objectAtIndex:currentIndex + 1];
[self updateNavigationBar];
return contentViewController;
}
-(void) updateNavigationBar{
if (CGPDFDocumentGetNumberOfPages(PDFDocument) > 1) {
title = [NSString stringWithFormat:@"Page %u of %u", currentIndex - 1, CGPDFDocumentGetNumberOfPages(PDFDocument)];
} else if ((CGPDFDocumentGetNumberOfPages(PDFDocument) < 1) {
title = [NSString stringWithFormat:@"Page %u of %u", currentIndex + 1, 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];
title = [[UINavigationItem alloc] initWithTitle:[NSString stringWithFormat:
@"Page %u of %u",
currentIndex,
CGPDFDocumentGetNumberOfPages(PDFDocument)]];
[_navBar pushNavigationItem:title animated:NO];
請幫的代碼。
欣賞它。
謝謝。
當我打開網頁在它轉換成標題的後退按鈕項後退按鈕項目和更新標題。 – user1120133
當我點擊backbuttonitem我可以看到標題滑動,並最終顯示爲後退項目 – user1120133
在視圖控制器上,您要更新導航欄標題(在'viewDidLoad'方法),只需更改當前目錄的'navigationItem'的標題view controller:'self.navigationItem.title = @「Custom Title」;' – Malloc