how to not call viewdidload in uinavigationcontroller?

后端 未结 3 1393
庸人自扰
庸人自扰 2021-01-29 12:21

I am looking for a solution to my situation. My app is as followed:

On VC1 there is a textfield and button. User types a name. Then click on a button. This button open V

相关标签:
3条回答
  • 2021-01-29 13:13

    I am afraid that why you are using push segue to move back.

    Here you need to assing a push segue from VC-A to VC-B and name its identifier like moveForward and button press call

    [self performSegueWithIdentifier:@"moveForward" sender:self]; 
    

    and if any information u want to pass to VC-B pass it in this method

     - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
       {
        if([segue.identifier isEqualToString:@"moveForward"])
        {
            VC-B* vcObject=[segue destinationViewController];
    
            //vcObject.info = your info//etc
        }
       }
    

    In a same way when u have to return to VC-A from VC-B assign a rewind segue from VC-B to VC-A and name its identifier like moveBack and on button press and do the above mention method in VC-B too.

    0 讨论(0)
  • 2021-01-29 13:20

    viewDidLoad method is called only once per lifecycle of UIViewController, so most probably you are creating somehow new VC1. You need keep reference to first VC1 and go back to that view controller.

    To navigate using UINavigationController use those methods:

    [self.navigationController pushViewController:VC2];
    
    [self.navigationController popViewControllerAnimated:YES];
    

    (call them inside VC1 / VC2)

    0 讨论(0)
  • 2021-01-29 13:27

    here is how you can define singleton class that is called AppShareData : AppShareData.h

    @interface AppSharedData : NSObject
    +(AppSharedData*)sharedInstance ;
    @property (nonatomic) BOOL sharedBoolVariable ;
    @end
    

    AppShareData.m:

    @implementation AppSharedData
    @synthesize sharedBoolVariable;
    +(AppSharedData *) sharedInstance
    {
       static AppSharedData *_sharedInstance = nil;
       static dispatch_once_t Token;
       dispatch_once(&Token, ^{
         _sharedInstance = [[AppSharedData alloc]init];
       });
      return _sharedInstance;
    }
    @end
    

    and then if you want to edit or set the value of the variable in any class i would do the following :

    -(void)editMethod
    {
       AppSharedData * dataObject = [AppSharedData sharedInstance] ; 
       dataObject = YES ; 
    }
    

    and if i want to retrieve the value of the variable in any class i do the following :

    -(void)retrieveMethod
    {
       AppSharedData * dataObject = [AppSharedData sharedInstance] ; 
       BOOL someVariableInMyClass = [dataObject sharedBoolVariable] ; 
    }
    
    0 讨论(0)
提交回复
热议问题