Back button is not visible in Navigation Bar in iPhone OS 4.0 in iPhone

点点圈 提交于 2019-12-11 13:06:38

问题


In my application (View based), the back buttons are not visible in the navigation bar. If I click that button, the actions works properly. It's very weird to me. The back button is visible and properly working in iPhone OS 3.0 and others.(Except OS 4.0). I am currently working in iPhone OS 4.0.

Here is my code:

UIButton *btn=[[UIButton alloc] init];

[btn setImage:[UIImage imageNamed:@"Back.png"] forState:UIControlStateNormal];

[btn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, 70, 0, 20)];
UIBarButtonItem *b=[[UIBarButtonItem alloc] initWithCustomView:btn];    
self.navigationItem.leftBarButtonItem=b;
[b release];
[btn release]; 

Note: It doesn't work only iPhone OS 4.0. So how can I achieve this?


回答1:


Simply you replace this code wherever you want and its working fine in OS 4.0.

UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];

[myView addSubview:btn];

UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,50,30)];

[myImage setImage:[UIImage imageNamed:@"Back.png"]];

[myView addSubview:myImage];

[btn addTarget:self action:@selector(lOut) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *b1 = [[UIBarButtonItem alloc] initWithCustomView:myView];

self.navigationItem.leftBarButtonItem = b1;

[btn release];

[b1 release];

[myView release];

[myImage release];

I hope it will help ypu.




回答2:


UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 40)];
[btn setImage:[UIImage imageNamed:@"info44.png"] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:@"info44_glowing.png"] forState:UIControlStateHighlighted];   
[btn addTarget:[AppDelegate sharedAppDelegate]  action:@selector(settingAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *settingButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem = settingButton;
[btn release];
[settingButton release];


来源:https://stackoverflow.com/questions/3124110/back-button-is-not-visible-in-navigation-bar-in-iphone-os-4-0-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!