gpt4 book ai didi

ios - 为什么 NavgationItem 引用消失了?

转载 作者:行者123 更新时间:2023-11-29 00:01:22 26 4
gpt4 key购买 nike

我创建了一个 NavigationBar 并将其添加到 UIViewController 中。但在init之后,引用变成nil。我是 iOS 和 OC 的新手,我不知道为什么。任何人都可以帮忙吗?谢谢。

代码摘要:

@interface ContainerViewController() 
@property (nonatomic, retain) UINavigationBar *nav;
@property (nonatomic, retain) UINavigationItem *navItem;
@end

@implementation ContainerViewController

- (instancetype) initWithParams:(NSDictionary *)params {
self = [super init];
if (self) {//...}
return self;
}

- setNavTitle:(NSDictionary *) params {
NSString *title = params[@"title"];
/////////////////////////////////
// here goes wrong
// self.navItem == nil here, why?
/////////////////////////////////
self.navItem.title = title;
}

- (void) viewWillAppear:(Bool)animated {
[super viewWillAppear:NO];

static float navHeight = 64.0;
UIViewController *wvController = [WebView init here];
UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), navHeight)];

UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:title];
nav.items = [NSArray arrayWithObjects: navItem, nil];

///////////////////////////////
// I saved the reference here
//////////////////////////////

[self setNav:nav];
[self setNavItem:navItem];

[self.view addSubview:nav];
[self addChildViewController:wvController];
wvController.view.bounds = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - navHeight);
[self.view addSubview:wvController.view];
[wvController didMoveToParentViewController:self];
}

@end

最佳答案

关于ios - 为什么 NavgationItem 引用消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49425212/

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