Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用else字符串中的字符串并在其他视图中显示_Ios_Objective C_If Statement_Uiview - Fatal编程技术网

Ios 使用else字符串中的字符串并在其他视图中显示

Ios 使用else字符串中的字符串并在其他视图中显示,ios,objective-c,if-statement,uiview,Ios,Objective C,If Statement,Uiview,如果If-Else语句在其他视图控制器中显示Else,我需要帮助显示字符串。我是新来的,如果你觉得这很愚蠢,我很抱歉。我在ViewControler.m文件中尝试过: -(IBAction)ButtonTouched:(id)sender { [self.InputField resignFirstResponder]; if (NSOrderedSame == [self.InputField.text caseInsensitiveCompare:@"teacher"])

如果If-Else语句在其他视图控制器中显示Else,我需要帮助显示字符串。我是新来的,如果你觉得这很愚蠢,我很抱歉。我在ViewControler.m文件中尝试过:

-(IBAction)ButtonTouched:(id)sender
{
    [self.InputField resignFirstResponder];
    if (NSOrderedSame == [self.InputField.text caseInsensitiveCompare:@"teacher"])
    {
        _Correct.hidden = FALSE;
        _Hider.hidden = TRUE;
        _FalseHider.hidden = FALSE;
        _SHOWCORRECT.hidden = TRUE;
        _CorrectAnswer.hidden = TRUE;
    } else {
        _FalseHider.hidden = TRUE;
        _Correct.hidden = TRUE;
        _SHOWCORRECT.hidden = FALSE;
        _CorrectAnswer.hidden = TRUE;

        NSString *ElseLabel = [NSString stringWithFormat:@"teacher"];
        self.OutputLabel.text = ElseLabel;
    }
}
Elselabel
位于主板的另一个ViewController中…。当我通过模态序列到达那里时,它不会显示任何东西!谢谢大家的回复

完成这些步骤

  • 转到Appdelegate.h并添加如下NSString

    @属性(非原子,保留)NSString*lableString

  • 转到Appdelete.m并合成字符串

    @综合扁豆

  • 然后像这样更改函数//别忘了#导入“AppDelegate.h”

  • 在你的不同观点中,使用这个

    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    self.OutputLabel.text = appDelegate.lableString;
    

  • 不是:-这不是最好的方法,但肯定会给你上一课

    FYI-标准做法是以大写字母开头类名,以小写字母开头方法和变量名。以下标准约定使您的代码更易于阅读。在Objective-C中,
    BOOL
    变量应设置为
    YES
    NO
    。您在何时何地触发模式segue?它连接到一个按钮。您是否使用上述代码中的相同按钮进行分段?对不起,还有一件事,我在哪里做第四步?我基本上有两个视图控制器和一个ViewControler.h和.m文件…所以上面所有的代码都在一个名为Tester.m的文件中,没有ViewControler.m…我应该创建一个新文件吗?如果是,如何连接?
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    self.OutputLabel.text = appDelegate.lableString;