我有 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 。所以,我检查并调试。我发现了这一点。它始终为零。我该怎么办?可能出现的错误有哪些?
编辑:我也在IB中连接过。
最佳答案
如果您没有使用此方法打开此 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/