iOS UI之删除导航栏左侧按钮

今天在网上搜了好多解决方案,一直没有解决这个问题,按理说将leftBarButtonItem置为nil就可以了,但是问题依然存在

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Register cell classes
    [self.collectionView registerNib:[UINib nibWithNibName:@"MovieCollectionViewCell" bundle:nil] 
          forCellWithReuseIdentifier:reuseIdentifier];
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    // 删除导航栏左侧按钮
    self.navigationItem.leftBarButtonItem = nil;
    
    // 导航栏添加右侧按钮
    self.navigationItem.rightBarButtonItem = ({
        UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_list.png"] 
                                      style:UIBarButtonItemStyleDone target:self action:@selector(backButtonAction:)];
        rightBtn;
    });
    
    // 加载数据
    [self loadData];
}


包括

    self.navigationItem.leftBarButtonItem = [UIBarButtonItem new];
同样没有效果。

迫不得已,我新建了一个UIBarButtonItem对象,将它的title属性设为空,问题解决了

    // 删除导航栏左侧按钮
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]init];
    barBtn.title=@"";
    self.navigationItem.leftBarButtonItem = barBtn;</span>

另一种解决方法:

    self.navigationItem.hidesBackButton = YES;


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值