我无法重命名NavigationBar的backBarButtonItem。并且系统backBarButtonItem没有出现

时间:2019-07-15 10:49:51

标签: objective-c

我无法重命名backBarButtonItem或在rightBarButtonItem(NavigationBar'item)中设置navigationBar。通常,当我按下另一个ViewController时,系统backBarButtonItem会出现,但也不会出现。

这是在ios 12中,我尝试设置backBarButtonItemleftBarButtonItemrightBarButtonItem,但还是失败了。

在以前的VC中:

- (IBAction)editInfo:(id)sender {
    YHPersonalInfoViewController *infoVC = [[YHPersonalInfoViewController alloc] init];
    //接收回调的用户信息
    __weak typeof (self)weakself = self;
    infoVC.userInfoBlock = ^(NSString *name, NSString *sex, NSString *age) {
        weakself.nameLabel.text = name;
        weakself.sexLabel.text = sex;
        weakself.ageLabel.text = age;
    };

    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:infoVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;

    [self setupBackButtonItemWithImage:[UIImage imageNamed:@"whiteback"] tintColor:[UIColor whiteColor] andTitle:@"编辑信息"];
}

- (void)setupBackButtonItemWithImage:(UIImage *)backIndicatorImage tintColor:(UIColor *)tintColor andTitle:(NSString *)title {
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationController.navigationBar.tintColor = tintColor;
    self.navigationController.navigationBar.backIndicatorImage = backIndicatorImage;
    self.navigationItem.backBarButtonItem = backItem;
}

在下一个VC中:

//测试导航栏右侧按钮
    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"预约记录" style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnItemClick)];
    self.navigationItem.rightBarButtonItem = rightBtnItem;

    NSLog(@"navigationItem%@",self.navigationItem);

    //测试导航栏左侧按钮
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, 0, 100, 20);
    [leftBtn setTitle:@"预约确认单" forState:UIControlStateNormal];
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:19.f];
    UIImage *img = [[UIImage imageNamed:@"whiteback"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [leftBtn setImage:img forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClick) forControlEvents:UIControlEventTouchUpInside];
    //ios11之后改变按钮偏移量的做法
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);
    leftBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 0);
    UIBarButtonItem *leftBarBtn = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarBtn;

    self.navigationController.navigationBar.barTintColor = [UIColor grayColor];

我已经迷恋了两天了,什么都没发生。

0 个答案:

没有答案