如何在推送到另一个ViewController时隐藏UINavigationBar?

时间:2018-05-10 05:12:24

标签: ios objective-c alert navigationbar

我有一个ViewController,“ViewController A”,我想推送到另一个ViewController,“ViewController B”。当我推送到ViewController B时,如果用户不是有效用户,我将检查用户验证并显示弹出警报。

如何隐藏UINavigationBar,因为我当前的代码无法正常工作。请帮忙。谢谢!

ViewController A

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if(indexPath.row==0) //Wishlist
    {
            WishList_ViewController *WishList_ViewControl = [[WishList_ViewController alloc]init];
           // [self cw_presentViewController:WishList_ViewControl];
         [self cw_pushViewController:WishList_ViewControl];
    }
}

ViewController B

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"My Wishlist";

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"])
    {
        //THIS CODE DOES NOT WORKING
        [self.navigationController setNavigationBarHidden:YES animated:YES];

        //Check whether is login or not
        SCLAlertView *alert = [[SCLAlertView alloc] init];
        [alert addButton:@"Done" target:self selector:@selector(btnLoginClick:)];
        alert.customViewColor = ThemeBlueColor;
        [alert showWaiting:self title:@"Login" subTitle:@"Please login to view your wishlist"
          closeButtonTitle:nil duration:2.0f ];

        [alert alertIsDismissed:^{
            [self btnLoginClick:nil];
        }];
    }
}

当前结果: enter image description here

1 个答案:

答案 0 :(得分:1)

请尝试此代码

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"My Wishlist";

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"])
    {

        self.navigationController.navigationBar.hidden=YES;

        //Check whether is login or not
        SCLAlertView *alert = [[SCLAlertView alloc] init];
        [alert addButton:@"Done" target:self selector:@selector(btnLoginClick:)];
        alert.customViewColor = ThemeBlueColor;
        [alert showWaiting:self title:@"Login" subTitle:@"Please login to view your wishlist"
          closeButtonTitle:nil duration:2.0f ];

        [alert alertIsDismissed:^{
            [self btnLoginClick:nil];
        }];
    }
}