I am making an Iphone app and I have a user click a button and it changes the sorting in my fetched results controller. However after I close my app it changes back to the original way it was sorted. i was just wondering if there is anyway to keep that button pressed when the app reopens.
- (IBAction)btnValue:(id)sender {
self.model.frc_Work.delegate = self;
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"Value" ascending:YES];
self.model.frc_Work.fetchRequest.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
}
Yes. Just use
NSUserDefaultsto store information:then, when you’re laying out your button:
NSUserDefaultsis basically anNSDictionarythat persists across app launches. It only stores property-list values (NSNumber, NSString, NSData, NSArray, NSDictionary, and NSDate) and primitives likeBOOLs.Here’s an example project demonstrating this using a
UISwitch: https://github.com/MaxGabriel/ButtonPersistence