2

的後退按鈕我有這樣的代碼,如果我把它放在viewDidLoad方法,它工作正常,改變我的UINavigationBar的改變UINavigationBar的

// Set the custom back button 
UIImage *buttonImage = [UIImage imageNamed:@"backag.png"]; 

//create the button and assign the image 
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setImage:buttonImage forState:UIControlStateNormal]; 
[button setImage:[UIImage imageNamed:@"selback.png"] forState:UIControlStateHighlighted]; 
button.adjustsImageWhenDisabled = NO; 


//set the frame of the button to the size of the image (see note below) 
button.frame = CGRectMake(0, 0, 30, 30); 

[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 

//create a UIBarButtonItem with the button as a custom view 
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 
self.navigationItem.leftBarButtonItem = customBarItem; 

// Cleanup 
[customBarItem release]; 

的後退按鈕。但是,當我加載下一個視圖時,舊式樣按鈕顯示出來。爲了解決這個問題,我試着把這段代碼放到下一個視圖的viewDidLoad方法中,但是沒有看到任何按鈕。

有關可能會導致此問題的任何想法?

謝謝!

回答

1

我用那朵代碼視圖和它的工作罰款...

//添加按照您同時查看的viewDidLoad方法的代碼...

UIButton *leftButton1 = [UIButton buttonWithType:UIButtonTypeCustom];  
[leftButton1 setImage:[UIImage imageNamed:@"Viewone.png"] forState:UIControlStateNormal];  
leftButton1.frame = CGRectMake(0, 0, 30, 30); 
[leftButton1 addTarget:self action:@selector(yourclickevent) forControlEvents:UIControlEventTouchUpInside];   
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton1]; 
[leftButton1 release]; 

UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];  
[leftButton setImage:[UIImage imageNamed:@"ViewSecond.png"] forState:UIControlStateNormal];  
leftButton.frame = CGRectMake(0, 0, 30, 30); 
[leftButton addTarget:self action:@selector(yourclickevent) forControlEvents:UIControlEventTouchUpInside];   
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; 
[leftButton release]; 

希望,這將幫助你... ..享受

2

應用相同的代碼在

-(void)viewDidAppear:(BOOL)animated 
{ 

} 
0

你需要確保你設置hidesBackButton親導航項目:

// Setup custom back button 
self.navigationItem.hidesBackButton = YES;