The essence of the application is to compare the current date with the specified one and display the text for each day (prayer time) ... Problem: when the application is in the background text for the current day it does not show. If you close the application and then open everything shows correctly. Help me please! THANK!

ViewController.h

@interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *utr; @property (weak, nonatomic) IBOutlet UITextField *voskh; @property (weak, nonatomic) IBOutlet UITextField *obed; @property (weak, nonatomic) IBOutlet UITextField *predz; @property (weak, nonatomic) IBOutlet UITextField *vecher; @property (weak, nonatomic) IBOutlet UITextField *noch; 

ViewController.m

 - (void)viewDidLoad { [super viewDidLoad]; NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSDateComponents *comp0 = [[NSCalendar autoupdatingCurrentCalendar] components:NSCalendarUnitEra | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:[NSDate date]]; NSDateComponents *comp1 = [calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth ) fromDate:[NSDate date]]; NSDateComponents *comp2 = [calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth ) fromDate:[NSDate date]]; NSDateComponents *comp3 = [calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth ) fromDate:[NSDate date]]; NSDateComponents *comp4 = [calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth ) fromDate:[NSDate date]]; [comp1 setDay:1]; [comp1 setMonth:1]; [comp2 setDay:2]; [comp2 setMonth:1]; [comp3 setDay:3]; [comp3 setMonth:1]; [comp4 setDay:4]; [comp4 setMonth:1]; if([comp1 day] == [comp0 day] && [comp1 month] == [comp0 month] ) { _utr.text=@"05:44"; _voskh.text=@"07:19"; _obed.text=@"11:58"; _predz.text=@"14:12"; _vecher.text=@"16:31"; _noch.text=@"18:01"; } if([comp2 day] == [comp0 day] && [comp2 month] == [comp0 month] ) { _utr.text=@"05:44"; _voskh.text=@"07:19"; _obed.text=@"11:58"; _predz.text=@"14:13"; _vecher.text=@"16:31"; _noch.text=@"18:01"; } if([comp3 day] == [comp0 day] && [comp3 month] == [comp0 month] ) { _utr.text=@"05:44"; _voskh.text=@"07:19"; _obed.text=@"11:59"; _predz.text=@"14:14"; _vecher.text=@"16:32"; _noch.text=@"18:02"; } if([comp4 day] == [comp0 day] && [comp4 month] == [comp0 month] ) { _utr.text=@"05:44"; _voskh.text=@"07:19"; _obed.text=@"12:00"; _predz.text=@"14:15"; _vecher.text=@"16:33"; _noch.text=@"18:03"; } 
  • All this code needs to be re-run when a notification arrives that the application has become active - Max Mikheyenko
  • @MaxMikheyenko Yes, yes ..)) But how? - Muhammadnakshubandi
  • @MaxMikheyenko if I could get the benefit out of such information ... - Muhammadnakshandi Omarov
  • swift or objc? - Max Mikheyenko

2 answers 2

Subscribe to the notice:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myCoolSelector:) name:UIApplicationDidBecomeActiveNotification object:NULL]; 

Run method:

 - (void)myCoolSelector:(NSNotification*)notification { //ваш код здесь } 

do not forget to unsubscribe in delloke

 - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } 

    Here is for you in Russian

    All these methods have system alerts, add an observver to the applicationDidBecomeActive , reboot the text calculation function at this event, that is, you need to put the code that you have in viewDidLoad into a separate function and call it in two cases: viewDidLoad and applicationDidBecomeActive.

    Update example:

     NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationDidBecomeActiveNotification, object: nil, queue: nil) { (notification) -> Void in reloadScreenText() }) 

    Now when the application returns to active mode, the reloadScreenText () method will be called in your controller.

    • stackoverflow.com/questions/11928126/… I found this but I cannot integrate it into my application ... where selector is your method. What method should be put there. applicationDidBecomeActive is the same delegate method. It can not be put viewcontroller. - Muhammadnakshubandi
    • In iOS, there is an NSNotificationCenter, which receives alerts from both the system and those created by the application (programmer). You can add an Observer for any alert, in this case for applicationDidBecomeActive. I will add an example to swift in the answer. - FreeGor