导航栏上的按钮不加载

我想在导航栏上添加按钮,但它不会加载在bar.Please help.Following是我的code.please告诉我我要去哪里错了。我使用的视图是风景导航栏上的按钮不加载

- (void)viewDidLoad { 

[super viewDidLoad];

CGRect rect = CGRectMake(0.0, 0.0, 480.0, 32.0);

navBar = [[UINavigationBar alloc] initWithFrame:rect];

navBar.items = self.navigationController.navigationBar.items;

navBar.delegate = self;

//[navBar release];

navBar.tintColor =[UIColor blackColor]

UIBarButtonItem * rightButton = [[UIBarButtonItem alloc]initWithTitle:@"Photo" style:UIBarButtonItemStyleBordered target:self action:@selector(takePhoto)];

UIBarButtonItem * backButton = [[UIBarButtonItem alloc]initWithTitle:@"Camera List" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel:)];

self.navigationItem.rightBarButtonItem = rightButton;

self.navigationItem.leftBarButtonItem = backButton;

//navBar.topItem.rightBarButtonItem = rightButton;

// navBar.topItem.leftBarButtonItem = backButton;

[self.view addSubview:navBar];

[backButton release];

}

回答:

试试这个

(void)viewDidLoad { 

[super viewDidLoad];

CGRect rect = CGRectMake(0.0, 0.0, 480.0, 32.0);

navBar = [[UINavigationBar alloc] initWithFrame:rect];

navBar.items = self.navigationController.navigationBar.items;

navBar.delegate = self;

UINavigationItem *navigationItem = [UINavigationItem alloc];

[navBar pushNavigationItem:navigationItem animated:NO];

[navigationItem release];

UIBarButtonItem * rightButton = [[UIBarButtonItem alloc]initWithTitle:@"Photo" style:UIBarButtonItemStyleBordered target:self action:@selector(takePhoto)];

UIBarButtonItem * backButton = [[UIBarButtonItem alloc]initWithTitle:@"Camera List" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel:)];

self.navigationItem.rightBarButtonItem = rightButton;

self.navigationItem.leftBarButtonItem = backButton;

[self.view addSubview:navBar];

[backButton release];

[rightButton release];

}

以上是 导航栏上的按钮不加载 的全部内容, 来源链接: utcz.com/qa/260608.html

回到顶部