it possible to Pass Data with popViewControllerAnimated?

前端 未结 5 1349
清歌不尽
清歌不尽 2020-12-06 02:29

I came across an interesting problem, i have main ViewController let\'s call him MainVC with navigationController and i am doing performSegueWithIdentifier from him to Mine

5条回答
  •  北海茫月
    2020-12-06 02:57

    There is another way to pass data between views including popViewControllerAnimated and it's with a global var instance, so If you modify that Var in your detail view and after do the popViewControllerAnimated, you can call the new data in the viewWillAppear method.

    The first step is declare the Global var in main.h

    NSMutableArray * layerList;
    

    And now you have to call it in detail view.

    SecondView.m

    extern NSString *layerList;
    

    SecondView.h

    -(void)back{
        layerList = @"Value to send";
        [self.navigationController popViewControllerAnimated:YES];
    }
    

    Now you can use the information in the Master View after detect the pop action.

    FirstView.m

    extern NSString *layerList;
    

    FirstView.h

    -(void)viewWillAppear:(BOOL)animated{
       NSLog(@"This is what I received: %@",layerList);
    }
    

提交回复
热议问题