-1

I am setting Back and next Button as Navigation Bar item left button and right button.which have code below as

 //  Back Button

UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

   [aButton addTarget:self action:@selector(navigatehome)forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.leftBarButtonItem = aBarButtonItem;

//Next Button
 aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

[aButton addTarget:self action:@selector(navigatenext)forControlEvents:UIControlEventTouchUpInside];

[self.navigationItem setRightBarButtonItem:aBarButtonItem]

And Problem when animated:YES in statement

  CSA_info *h1=[[CSA_info alloc]init];
[self.navigationController pushViewController:h1 animated:YES];

It shows as below image

image when button not shown

If uses animated:No then showed as below

enter image description here

I am adding a image in as subview in navigation Bar so it hides the buttons.

 UIImage *image = [UIImage imageNamed:@"title bar.png"];
 UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
 imageView.frame = CGRectMake(-5, 0, 330, 44); 
 [self.navigationController.navigationBar insertSubview:imageView atIndex:2];

I required to add that image in navigation.

Why it so, Any Help ?

Arpit Kulsreshtha
  • 2,452
  • 2
  • 26
  • 52

2 Answers2

1

If I understood you problem properly then following solution should work,

You need to add the code in viewDidLoad method of the view controller. Please refer the below code

UIButton *backButton = [[UIButton alloc] initWithFrame:kButtonFrame];
[backButton setImage:[UIImage imageNamed:kBackButtonImage] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(navigatehome)forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = aBarButtonItem;

UIButton *nextButton = [[UIButton alloc] initWithFrame:kButtonFrame];
[nextButton setImage:[UIImage imageNamed:kNextButtonImage] forState:UIControlStateNormal];
[nextButton addTarget:self action:@selector(navigatenext)forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *aBarButtonItemRight = [[UIBarButtonItem alloc] initWithCustomView:nextButton];
[self.navigationItem setRightBarButtonItem:aBarButtonItemRight];

This should work fine even you animated while pushing the view controller.

Prasad Devadiga
  • 2,573
  • 20
  • 43
1

you need to put title bar image in secondViewcontroller like bellow in ViewDidLoad

UIImage* imageback = [UIImage imageNamed:@"Back_Button.png"];
                CGRect frameimgback = CGRectMake(0, 0, 50, 30);
                backButton = [[UIButton alloc] initWithFrame:frameimgback];
                [backButton setBackgroundImage:imageback forState:UIControlStateNormal];
                [backButton addTarget:self action:@selector(Back)
                     forControlEvents:UIControlEventTouchUpInside];

                UIImage *image = [UIImage imageNamed:@"titileBar.png"];
                [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

                UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithCustomView:backButton];
                self.navigationItem.leftBarButtonItem = btn;
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144