My code:
@interface BIDMyClass ()
@end
@implementation BIDMyClass {
UINavigationBar *settingsBar;
}
-(void)loadView {
[super loadView];
settingsBar = [[UINavigationBar alloc] init];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[settingsBar setFrame:CGRectMake(0.0f, 0.0f, 293.0f, 44.0f)];
[settingsBar.topItem setTitle:@"Settings"];
[self.view addSubview:settingsBar];
}
settingsBar
is added but there is no title on it. How can I fix it?
settingsBar.topItem
is probably nil. Try setting the list of items on your settingsBar
:
settingsBar.items = [NSArray arrayWithObject:[[[UINavigationItem alloc] initWithTitle:@"Settings"] autorelease]];
Alternatively you may also declare your:
IBOutlet UINavigationBar *navBar;
and connect in IB. Assuming you have an XIB file with the navBar on it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.