我有一个基于导航的应用程序,我想在其中隐藏显示在左侧的默认导航,并且我想添加我自己的自定义按钮。我编写了以下 2 个代码。
代码示例 1:
- (void)viewDidLoad {
appDelegate=[(FoodAppDelegate *)[UIApplication sharedApplication]delegate];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Volunteers_back.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 86, 30)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
但这会显示默认导航按钮。
第二个代码示例:
self.navigationItem.hidesBackButton=YES;
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
[barButton setImage:[UIImage imageNamed:@"Volunteers_back.png"]];
[self.navigationItem setLeftBarButtonItem:barButton];
这个显示按钮默认和自定义相互重叠。有谁知道这里有什么问题?或任何示例代码来实现这一点?