简体   繁体   中英

the back button not changing in iOS

i have to change the back button image. So for achieveing this i am using the following code:

       //add the back button.
    UIButton *home = [UIButton buttonWithType:UIButtonTypeCustom];  
    UIImage *homeImage = [UIImage imageNamed:@"back.png"];  
    [home setBackgroundImage:homeImage forState:UIControlStateNormal];  
    [home addTarget:self action:@selector(cancel:)  
   forControlEvents:UIControlEventTouchUpInside];  
    home.frame = CGRectMake(0, 0, 30, 30); 
    UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc]  
                                      initWithCustomView:home] autorelease];
    self.navigationItem.backBarButtonItem = cancelButton; 

also the method cancel defined in this view controller. I use the above code in viewDidLoad method. I am still not able to see the back button. No button shows up in the navigation bar.

I am writing this code in the viewcontroller that is loaded, and not in the previous view.

thank you in advance.

You have to set it as leftBarButtonItem .

self.leftBarButtonItem.backBarButtonItem = cancelButton; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM