nsuserdefaults

iOS - NSUserDefaults value returns null for 'valueForKey' but isn't null

旧街凉风 提交于 2019-12-25 07:18:35
问题 I am trying to see if a user has made a purchase by retrieving the NSUserDefaults value for each product identifier. I save the value when a product is purchased and it is getting set correctly. The key-value pair show up correctly when calling this: NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]); As this: "com.COMPANY.PRODUCTIDENTIFIER" = 1; But when I try to actually validate that specific key-value it always returns null: for (NSString * productIdentifier in

iOS: Updating text labels with NSUserDefault data on different views

走远了吗. 提交于 2019-12-25 06:19:09
问题 I have a text label on view 1 and a button. If I click the button, I am brought to view 2 through a modal connection. In this view, I enter a number and press a button. The button saves the number to NSUserDefaults, as well as tries to update the text label on view 1 to reflect this number. Button's code: - (IBAction)returnToView1:(UIButton *)sender { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; defaults setObject:@"myNumber" forKey:@"myKey"]; [defaults synchronize];

iOS: Updating text labels with NSUserDefault data on different views

懵懂的女人 提交于 2019-12-25 06:19:06
问题 I have a text label on view 1 and a button. If I click the button, I am brought to view 2 through a modal connection. In this view, I enter a number and press a button. The button saves the number to NSUserDefaults, as well as tries to update the text label on view 1 to reflect this number. Button's code: - (IBAction)returnToView1:(UIButton *)sender { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; defaults setObject:@"myNumber" forKey:@"myKey"]; [defaults synchronize];

NSUserDefaults not getting stored string value

好久不见. 提交于 2019-12-25 05:31:04
问题 I have UIWebView for reading content. After that i select some text from content stores in string using NSUserDefaults in Viewcontroller. Then i retrieve this string value and displays in UITextView to viewcontroller1. But the UITextView is not updating text from viewcontroller. The NSUserDefaults also not getting updating text. Im using [self.navigationController pushViewController:viewcontroller1 animated:YES]; for switch to viewcontroller1. viewcontroller: [wbCont loadHTMLString:webString

NSUserDefaults not getting stored string value

雨燕双飞 提交于 2019-12-25 05:30:05
问题 I have UIWebView for reading content. After that i select some text from content stores in string using NSUserDefaults in Viewcontroller. Then i retrieve this string value and displays in UITextView to viewcontroller1. But the UITextView is not updating text from viewcontroller. The NSUserDefaults also not getting updating text. Im using [self.navigationController pushViewController:viewcontroller1 animated:YES]; for switch to viewcontroller1. viewcontroller: [wbCont loadHTMLString:webString

Not all NSUserDefaults are restored on app relaunch

纵然是瞬间 提交于 2019-12-25 05:19:30
问题 I am converting 2 custom lists into a json string and storing it the NSUserDefaults. Something like so:- NSUserDefaults.StandardUserDefaults.SetString(JsonConvert.SerializeObject(stationList.Take(50)), "StationList1"); NSUserDefaults.StandardUserDefaults.SetString(JsonConvert.SerializeObject(stationList.Skip(50).Take(50)), "StationList2"); If I try and retrieve them immediately after saving them like below I get the saved values:- savedStationList1 = NSUserDefaults.StandardUserDefaults

iOS store Array of Objects

孤街浪徒 提交于 2019-12-25 04:46:33
问题 In my application i implemented several tableviewcontrollers that display a NSObject for each cell. Every tableviewcontroller has a different "filter" that is applied to the array so every table displays a specific group of these objects. In the viewdidload of each tableviewcontroller i load my array from NSUserdefaults, filter it, and display it. This works just fine, i am using NSCoder to get the Objects encoded/decoded for storing. For developing purposes only, i create each Object

Why NSUserDefaults return 'nil'?

百般思念 提交于 2019-12-25 04:24:26
问题 can someone explain me why NSUserDefaults is returning me "nil" for an object that is not? I have a view with some settings for a game, there is a textfield in where user can write his name. I save this name in NSUserDefaults and put it as placeholder for the other times user enter this view. I set the object like that: NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults]; NSString *fieldName = _nameField.text; [defaults setObject:fieldName forKey:@"playerName"]; [[NSUserDefaults

How to save a BOOL in iOS app

风流意气都作罢 提交于 2019-12-25 04:19:47
问题 I used the following code to save a BOOL but it's not working. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"save"]; StrongMAN = [[NSUserDefaults standardUserDefaults] boolForKey:@"save"]; Are there other ways to save a BOOL ? 回答1: You should add the following code [[NSUserDefaults standardUserDefaults] synchronize]; 回答2: [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"kLogIn"]; [[NSUserDefaults standardUserDefaults] synchronize]; 回答3: [[NSUserDefaults

Use data from NSUserDefaults in UIPickerView - pickerView stays empty

拈花ヽ惹草 提交于 2019-12-25 04:14:23
问题 I tried to set up NSUserDefaults last night but an error keeps occurring: ViewController3: save data @IBAction func tappedAddButton(sender: AnyObject) { var userDefaults:NSUserDefaults = NSUserDefaults.standardUserDefaults() var exercisesList:NSMutableArray? = userDefaults.objectForKey("exercisesList") as? NSMutableArray var dataSet:NSMutableDictionary = NSMutableDictionary() dataSet.setObject(textField.text, forKey: "exercises") if ((exercisesList) != nil){ var newMutableList:NSMutableArray