如果我有一个UILabel节省了时间,使用以下代码保存在plist中。现在我想加载时间,例如凌晨1:00,在故事板中的另一个视图控制器中的UIPicker上显示时间(凌晨1:00)。如何做到这一点?
由于
- (void)viewDidLoad
{NSString *myPath = [self saveFilePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
if (fileExists)
{
NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
morningtime.text = [values objectAtIndex:0];
afternoontime.text = [values objectAtIndex:1];
}
UIApplication *myApp = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:myApp];
[super viewDidLoad]; }
- (NSString *) saveFilePath
{
NSArray *path =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[path objectAtIndex:0] stringByAppendingPathComponent:@"savefile.plist"];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSArray *values = [[NSArray alloc] initWithObjects:morningtime.text,afternoontime.text,nil];
[values writeToFile:[self saveFilePath] atomically:YES];
}