• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

导航栏上的按钮不加载

iphone 来源:Dipti Y W 10次浏览

我想在导航栏上添加按钮,但它不会加载在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]; 
} 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)