开发者

the back button not changing in iOS

开发者 https://www.devze.com 2023-03-17 03:43 出处:网络
i have to change the back button image. So for achieveing this i am using the following code: //add the back button.

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.navigati开发者_C百科onItem.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; 
0

精彩评论

暂无评论...
验证码 换一张
取 消