How to get the nsuserdefault value in other viewcontrollers

前端 未结 4 627
迷失自我
迷失自我 2020-12-25 09:08

I have two viewcontrollers. In my first viewcontroller:

{           
    NSString *string=textField.text;  
    NSUserDefaults *data = [NSUserDefaults standa         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-25 09:37

    NSUserDefaults * defaults =  [NSUserDefaults standardUserDefaults]; 
    NSString *myString = [defaults stringForKey:@"strings"];
    

    THis is the way to retrieve the data. Please note NSUserDefault is not used to pass data between two controllers. There are better methods for that.

    Edit : After seeing Shaan Singh's comment

    To pass data 2 view controllers you can declare a property in second view controller and access that from the present view controller.

    It is already answered brilliantly here.

提交回复
热议问题