导航栏上的按钮未加载

发布于 2024-11-16 20:59:34 字数 1041 浏览 3 评论 0原文

我想在导航栏上添加按钮,但它没有加载到导航栏上。请帮忙。以下是我的代码。请告诉我哪里出错了。我使用的视图是横向

- (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];
}

i want to add buttons on navigation bar but its not loading on bar.Please help.Following is my code.please tell me where i am going wrong.The view i am using is landscape

- (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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

極樂鬼 2024-11-23 20:59:34

试试这个

(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];
}

try this

(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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文