how to not call viewdidload in uinavigationcontroller?

后端 未结 3 1392
庸人自扰
庸人自扰 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: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] ; 
    }
    

提交回复
热议问题