gpt4 book ai didi

objective-c - 插入 UINavigationController 堆栈的 UIViewController 丢失 UIAppearance 设置

转载 作者:行者123 更新时间:2023-12-02 05:18:23 25 4
gpt4 key购买 nike

我的导航栏有一个 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];
}

一切正常。在我的应用程序中的某个时刻,我需要将一个 View Controller 插入堆栈并弹出到它。

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];

此时,标题栏失去外观设置,恢复为默认的白色。任何插入堆栈的新 View Controller 也会丢失它们的外观。

有什么问题?

最佳答案

如果你在 appDelegate 类中自定义它,那么这个问题就永远不会出现。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Code.........

[[UINavigationBar appearance] setTitleTextAttributes: [self navigationBarTitleTextAttributes]]
}

-(NSDictionary *)navigationBarTitleTextAttributes
{

// NSNumber *navBarTitleShadowOpacity = [self.personalityDictionary objectForKey:kNavBarTitleShadowOpacity];
UIColor *navBarTitleColor = [UIColor redColor];//: [self.personalityDictionary objectForKey:kNavBarTitleColor] alpha:1.0f];
UIColor *navBarTitleShadowColor = [UIColor greenColor];//colorWithHexString:[self.personalityDictionary objectForKey:kNavBarTitleShadowColor] alpha: [navBarTitleShadowOpacity floatValue]];

return [NSDictionary dictionaryWithObjectsAndKeys:
navBarTitleColor, UITextAttributeTextColor,
navBarTitleShadowColor, UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil];
}

希望对你有帮助。

关于objective-c - 插入 UINavigationController 堆栈的 UIViewController 丢失 UIAppearance 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15693265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com