I have the following:

header file:

 UINavigationBar *navigationBar;
  UINavigationItem *navigationItem;

implementation file: in viewDidLoad method I tried these:

self.navigationBar.topItem.title = @"title text";

and also this:

  self.navigationItem.title = @"MyTitle";
  [self.navigationBar pushNavigationItem:navigationItem animated:NO];

But no title seems to appear on the black up bar:

enter image description here

Has anyone any idea?Thank you! EDIT: enter image description here

有帮助吗?

解决方案

  1. You should define in your class property:

    @property (nonatomic, assign) IBOutlet UINavigationBar *navigationBar;

  2. You should set that class as File's Owner.

  3. You should connect your navigation bar with property from 1. (Using IBOutlet)
  4. Now you can set its title using : self.navigationBar.topItem.title = @"title text";

其他提示

Try this:-

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.font = [UIFont boldSystemFontOfSize:14.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = [dataItem objectForKey:@"title"];
[label release];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top