當我嘗試在啓動之間恢復UINavigationController的狀態時,我遇到了UIBarButtonItem/UINavigationBar的一些奇怪行爲。在恢復狀態導航控制器後截斷後退按鈕標題
下面的代碼片段顯示了我如何恢復導航控制器的狀態。此代碼片段在viewDidLoad方法中執行。
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if ([ud objectForKey:HBStateRestorationQuoteSelection]) {
NSInteger index = [ud integerForKey:HBStateRestorationQuoteSelection];
// Fetch Quote
NSDictionary *quote = [self.quotes objectAtIndex:index];
// Initialize Quote View Controller
HBQuoteViewController *vc = [[HBQuoteViewController alloc] initWithNibName:@"HBQuoteViewController" bundle:[NSBundle mainBundle]];
vc.quote = quote;
// Push Quote View Controller Onto Navigation Stack
[self.navigationController pushViewController:vc animated:NO];
}
結果是由於某種原因截斷了後退按鈕標題。導航控制器以正常方式使用時,此行爲不存在。
請注意,截斷不是由於導航欄中標題的大小。正如我前面提到的,當我不使用這種狀態恢復邏輯時,後面條按鈕的標題顯示正常。
我也嘗試將恢復代碼放在viewWillAppear方法中,或者通過創建自定義後退按鈕來更改後欄按鈕的標題,但這些方法都不能解決問題。