getting view controller variable and putting it into the app delegate
I'm trying to make my timer "run" in the background by saving the time to
disk on entering background and retrieving it on entering foreground. Each
view controller has a timer and a timeInterval specified by the user. The
problem is, I don't know how to access the timeInterval variable. I think
I can get the difference of time by using something like this (would this
work?):
NSTimeInterval idleTime = [dateReturnedToForeground
timeIntervalSinceDate:dateEnteredBackground];
NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate:startDate];
elapsedTime -= idleTime;
Each view controller (and timer/time interval) is accessed like this:
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC;
if (![self.detailViewsDictionary.allKeys containsObject:indexPath]){
detailVC = [[DetailViewController
alloc]initWithNibName:@"DetailViewController" bundle:nil];
[self.detailViewsDictionary setObject:detailVC forKey:indexPath];
detailVC.context = self.managedObjectContext;
}else{
detailVC = self.detailViewsDictionary[indexPath];
}
Tasks *task = [[self fetchedResultsController]
objectAtIndexPath:indexPath];
detailVC.testTask = task;
[[self navigationController] pushViewController:detailVC
animated:YES];
NSLog(@"%@", self.detailViewsDictionary);
[[NSNotificationCenter defaultCenter] addObserver:detailVC
forKeyPath:self.detailViewsDictionary[indexPath] options:nil
context:nil];
}
I am adding each view controller to the Notification Center so it can be
accessed in the app delegate (i think this is right?). Problem is, I don't
know how to combine the first code with the view controller code, because
I can't access the view controller's properties in the app delegate. Any
suggestions so that I can make my timer "run" in the background?
No comments:
Post a Comment