Action to Navigation bar back button

前端 未结 6 1498
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 20:06

I want to show an alert with Confirmation when user clicks on back button. This is how I\'m trying to add action.

self.navigationItem.hidesBackButton = true
         


        
6条回答
  •  隐瞒了意图╮
    2020-12-19 20:56

    This might help. This wont override back action, but you can do additional task.

    Objective c

    -(void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        if(self.isMovingFromParentViewController)
        {
            //On click of back or swipe back
        }
        if(self.isBeingDismissed)
        {
            //Dismissed
        }
        NSLog(@"%d",self.isBeingDismissed);
        NSLog(@"%d",self.isMovingFromParentViewController);
    }
    

    Swift

    override func viewWillDisappear(_ animated: Bool)
    {
        super.viewWillDisappear(animated);
        if self.isMovingFromParentViewController
        {
            //On click of back or swipe back
        }
        if self.isBeingDismissed
        {
            //Dismissed
        }
    }
    

提交回复
热议问题