标签是特定文本时更改视图控制器?

时间:2014-10-12 02:44:19

标签: iphone xcode if-statement text label

我有一个QR码阅读器,它会在扫描某些内容时更改文本的标签。例如,如果我扫描QR码代码" nfl.com"它会显示" nfl.com"在标签上。我想在标签上出现某个文本时切换控制器。此文本基本上是一个帐号,因此您扫描QR码,帐号出现,它会自动将您更改为另一个视图控制器,其中显示该帐号的项目数组。

2 个答案:

答案 0 :(得分:0)

如果要检查字符串是否等于特定字符串,则在设置标签文本时可以执行以下操作:

label.text = string;

if ([string isEqualToString:@"Specific String"]) {
    ExampleViewController *exampleViewController = [[ExampleViewController alloc] init];
    [self.navigationController pushViewController:exampleViewController animated:YES
}

如果您想要延迟以便显示标签,那么在延迟推动下一个视图控制器后,您可以执行以下操作:

label.text = string;

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    //code to be executed on the main queue after delay
    if ([string isEqualToString:@"Specific String"]) {
        ExampleViewController *exampleViewController = [[ExampleViewController alloc] init];
        [self.navigationController pushViewController:exampleViewController animated:YES
    }
});

答案 1 :(得分:0)

我试过

    [_lblStatus performSelectorOnMainThread:@selector(setText:) withObject:[metadataObj stringValue] waitUntilDone:NO];


        if ([_lblStatus isEqual:@"A123"]) {
            NSString * storyboardName = @"Main_iPhone";
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
            UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"CheckViewController"];
            [self presentViewController:vc animated:YES completion:nil];

        }

我确实将标签更改为A123,但在此之后我无法切换到其他视图控制器。我试过你的答案@ferris但是我不能设置我的_lblStatus = string; (字符串会导致错误,除非我在.h文件中定义它。