【问题标题】:Condition check help xcode条件检查帮助 xcode
【发布时间】:2013-02-18 10:34:46
【问题描述】:

在 viewDidLoad 我在标签上显示一个文本

[label setText:@"hello"];

在某个事件之后我将其隐藏起来。现在我想要一个条件来检查

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

请帮我检查一下

【问题讨论】:

    标签: ios objective-c xcode uilabel


    【解决方案1】:

    你在寻找这样的东西吗?

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

    以及你可以使用的条件:

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

    【讨论】:

    • 虽然不是我想要的,但从你的回答中得到了提示..than ks:)
    【解决方案2】:

    要了解您的文字何时在屏幕上显示 30 秒,您需要使用计时器。 IO 的计时器类是NSTimer。查看Apple Dev Center 了解更多信息。

    您可能希望使用scheduleTimerWithInterval:target:selector:repeats 方法并将其设置为不重复,并将时间间隔设置为 30 秒。

    【讨论】:

      【解决方案3】:

      试试这个代码:

         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;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-16
        • 2011-10-03
        • 1970-01-01
        • 2021-10-25
        • 2017-04-14
        • 2012-02-04
        相关资源
        最近更新 更多