我为导航栏设置了 UIAppearance。
[[UINavigationBar appearance] setTitleTextAttributes: [self navigationBarTitleTextAttributes]];
-(NSDictionary *)navigationBarTitleTextAttributes
{
// UINavigationBar title
NSNumber *navBarTitleShadowOpacity = [self.personalityDictionary objectForKey:kNavBarTitleShadowOpacity];
UIColor *navBarTitleColor = [UIColor colorWithHexString: [self.personalityDictionary objectForKey:kNavBarTitleColor] alpha:1.0f];
UIColor *navBarTitleShadowColor = [UIColor colorWithHexString:[self.personalityDictionary objectForKey:kNavBarTitleShadowColor] alpha: [navBarTitleShadowOpacity floatValue]];
return [NSDictionary dictionaryWithObjectsAndKeys:
navBarTitleColor, UITextAttributeTextColor,
navBarTitleShadowColor, UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil];
}
一切都完美无缺。在我的应用程序中,我需要将一个视图控制器插入堆栈并弹出它。
ChatsViewController* chatsViewController = [[ChatsViewController alloc] init];
NSMutableArray *mutableViewControllers = [self.navigationController.viewControllers mutableCopy];
[mutableViewControllers insertObject: chatsViewController atIndex: [mutableViewControllers count] - 1];
[self.navigationController setViewControllers: mutableViewControllers animated: NO];
[self.navigationController popToViewController: chatsViewController animated: YES];
此时,标题栏失去了外观设置,回到了默认的白色。任何推入堆栈的新视图控制器也会失去其外观。
有什么问题?