nsuserdefaults

How do you save data for two text fields using NSUserDefaults?

假如想象 提交于 2019-12-12 01:38:23
问题 How do you save data for two text fields using NSUserDefaults on iOS? 回答1: For saving: [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:FirstTextView]; [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SecondTextView]; [[NSUserDefaults standardUserDefaults] synchronize]; For load: NSDate *textfield1Date = [[NSUserDefaults standardUserDefaults] objectForKey:FirstTextView]; NSDate *textfield2Date = [[NSUserDefaults standardUserDefaults] objectForKey

NSUserDefaults BOOL logic

孤街浪徒 提交于 2019-12-12 01:29:52
问题 I have a quiz game, where when the answer was correct, a picture with tick sign will appear. As I have many fields and need the app to remember which are done already for next launch. I am using NSUserDefaults. It is working great, but the problem is, that at the very first launch all "done" images are displayed. I was trying to get around the BOOL logic but no success. .h BOOL doneState; .m - (void)viewDidLoad{ [super viewDidLoad]; [self doneHidden]; [self checkBools]; } - (void)checkBools{

NsUserDefualts not functioning right

穿精又带淫゛_ 提交于 2019-12-12 00:37:31
问题 Basically I have some sort of bug with tableView, i noticed that my tableView is not always getting updated correctly, and i tried debugging it and what i noticed is that tableView class is not always getting called to update the table. What am i doing wrong ? When i add new entry to my table, count 4 + 1, I go to history tab, and nothing happens and it shows as the count is still 4 but if I switch tabs 1 more time it will show count as 5 and tableView will be updated.. so there is a delay in

bool saving problem

做~自己de王妃 提交于 2019-12-11 23:41:00
问题 Edited i've got a sound in my app which begins to play when the app is started. further I've got two method to play and stop the sound: -(void)playBgMusic { NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"]; theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; theAudio.delegate = self; [theAudio play]; [defaults setBool:NO forKey:@"isQuiet"]; } -(void)stopMusic { [theAudio stop]; [defaults setBool:YES forKey:@

Saving cell accessory to NSUserDefaults

霸气de小男生 提交于 2019-12-11 22:55:25
问题 I've previously asked a question which was answered here regarding saving the state of of a cell accessory. I'm now playing with NSUserDefaults. I've successfully saved a number of options in my app but can't seem to save the state of the cell accessory to NSUserDefaults. After a number of tries, I've come to the conclusion I don't know what or where to save as well as where to recall the saved options. Can anyoone point me in the right direction? Thanks, EDIT: Whilst I understand the

UITableView count not increasing

寵の児 提交于 2019-12-11 22:39:14
问题 I have UITextView in ViewController. Im passing the textView to viewcontroller1 UITableView. I used NSUserDefaults for store and retrieve text. In viewcontroller1 UITebleView is not increasing with updating text, it replacing old text in only first row. viewController: -(void)save:(id)sender{ NSUserDefaults *userData1 = [NSUserDefaults standardUserDefaults]; [userData1 setObject:textView.text forKey:@"savetext"]; [userData1 synchronize]; } ViewController1: -(void) viewWillAppear:(BOOL

Loading data in NSUserDefaults

此生再无相见时 提交于 2019-12-11 22:33:50
问题 i have done the coding to save the highscore in NSuserdefaults, but i am not sure how can i load the data from the nsuserdefaults and display it in a table. PLease help. NSString *name; name = nametextbox.text; NSDictionary *player = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@", name], @"name",[NSString stringWithFormat:@"%d", myScore], @"score",nil]; [highScore addObject:player]; NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"score" ascending

NSUserDefaults will not load data consistently

血红的双手。 提交于 2019-12-11 22:20:38
问题 I have a tab-based application and want to reload data each time I switch between the tabs. So I used viewWillAppear: which gets called but the data doesn't reload. Could this be a result of using lots of [NSUserDefault] 's? Here is my code: -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self reloadData]; } -(void)reloadData { //Loading all the data totalApples = [[NSUserDefaults standardUserDefaults]integerForKey:@"totalApples"]; [self setText:[NSString

How to retrieve UISwitch state in each of my UITableView cells?

淺唱寂寞╮ 提交于 2019-12-11 19:23:37
问题 I have a UISwitch set as the accessoryView in each of my TableView cells. If I press my Confirm button, I want to save the state of each UISwitch with NSUserDefaults. Then when I leave and go back to that View Controller, I should be able to load those saved states which will be different for each cell (either on or off, as shown in image). I'm almost there but I guess I am not sure how to save/load with the right indexPath.row so it's not working correctly. Right now it is just saving

Xcode using NSUserDefaults to save data on Master View Controller

醉酒当歌 提交于 2019-12-11 19:11:45
问题 I am creating a master detail app for the ipad that should save whatever the user is typing (using buttons on the popover view which puts some text on the label in that popover view) in the table view cel in master view controller. So basically I have a popover view that contains a UILabel called inputDisplayLabel and whatever button the user presses that buttons text goes in that UILabel. When enter button is pressed it adds that text to the tableviews cel. Now I want to save whatever is in