ios - navigationItem 总是变成 nil

标签 ios objective-c frame null uinavigationitem

我有 navigationItem 的 IBoutlet,我写为

@property (nonatomic,strong) IBOutlet UINavigationItem *navItemRoster;

然后,我编写设置标题 View 。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
        self.title = @"Select User";
        self.navItemRoster.titleView = [Helpers getCenterTitleViewWithTitle:@"Select User"];
    }
    return self;
}

但我无法设置标题 View 。所以,我检查并调试。我发现了这一点。它始终为零。我该怎么办?可能出现的错误有哪些?

enter image description here

编辑:我也在IB中连接过。

enter image description here

最佳答案

如果您没有使用此方法打开此 VC - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 那么您必须在 中编写此代码- (void)viewDidLoad 方法设置标题。

-(void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Select User";
    self.navItemRoster.titleView = [Helpers getCenterTitleViewWithTitle:@"Select User"];
}

关于ios - navigationItem 总是变成 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24754721/

相关文章:

PHP - 在视频上传期间提取帧

ios - 如何呈现较小尺寸的 View Controller

ios - 如何从屏幕上删除行?

ios - 如何检查持久存储?

ios - 当从 UIBarButtonItem 呈现时,如何防止 UIPopoverController passthroughViews 在方向更改后被重置?

ios - 从 C 库调用 objective-c 方法

ios - 通过将 UIView 添加到 UIStackView 来动画化 UIView 过渡

ios - 如何在同一个 UILabel 中添加多行

ios - 使用AFNetworking与OCMock的测试方法

objective-c - NSLocalizedString 中的注释标准