How to pop a viewController and then Push a viewController through delegation

后端 未结 5 1157
长情又很酷
长情又很酷 2021-02-09 00:56

I have a UITableViewController that when a cell is pressed, I want the controller to pop itself, and then have the controller it pop\'s to, push another view controller onto the

5条回答
  •  不要未来只要你来
    2021-02-09 01:13

    I liked Alexandre's solution but if I were a delegate person, I wouldn't want to use notification. So in that case, we can just use the delegate in the viewDidDisappear method.

    So, in the didSelectRowAtIndexPath method, you can pop the controller-

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
         [self.navigationController popViewControllerAnimated:YES];
    }
    

    and in the same View Controller, the ViewController you are popping, call the delegate method in the viewDidDisappear method like-

    -(void)viewDidDisappear:(BOOL)animated{
       [self.delegate cellPressedInTableViewControllerWithCalculationsModel:(id)anArgmentMyDelegateMethodTakes];
    }
    

    Then in the controller that is pushed can implement the delegate method and inside that delegate method, you can do whatever you want.

提交回复
热议问题