Xcode status checker reference

In viewDidLoad I am showing the text on the label

[label setText:@"hello"];

      

and after some event I will hide it. Now I want a condition to check

if([label.text isEqualToString:@"hello"] is visible on screen for >= 30 seconds)
{
//some code......
}

      

Please help me to do this check.

+3


source to share


3 answers


Are you looking for something like this?

    {
     //your method.
     [label setText:@"hello"];
     [self performSelector:@selector(afterDelay) withObject:nil afterDelay:30];
    }

   -(void)afterDelay {
    [label setText:@""];
    }

      



And the condition you can use:

   if(label.text.length == 0) {
   }

      

+3


source


To find out when your text has been on the screen for 30 seconds, you will need to use a timer. The timer class for IO is NSTimer

. For more information about it, check out the Apple Dev Center.



You probably want to use the method scheduleTimerWithInterval:target:selector:repeats

and set it not repetitive and the time interval is 30 seconds.

0


source


Try this code:

   if ([label.text isEqualToString:@"hello"]) {
            NSTimer * tm = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(hideLabel) userInfo:nil repeats:NO];
        }

    -(void)hideLabel {
          self.label.hidden = YES;
    }

      

0


source







All Articles