Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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
Iphone 预期表达式为iOS Xcode_Iphone_Macos_If Statement - Fatal编程技术网

Iphone 预期表达式为iOS Xcode

Iphone 预期表达式为iOS Xcode,iphone,macos,if-statement,Iphone,Macos,If Statement,我正在尝试制作一个简单的计算器应用程序,并按照视频中的说明进行操作() 然而,当我到达大约9:14时,我得到了一个错误,说“期望表达式”,在else语句之前有一些标记。我现在不能发布图片,所以请把你知道的一切都发布给我。我是个新手,任何帮助都将不胜感激 我的代码(ViewController.m): 你还有两个陈述。那是不可以的 - (IBAction)NumberPressed:(UIButton*)sender;{ NSInteger tag = sender.tag; i

我正在尝试制作一个简单的计算器应用程序,并按照视频中的说明进行操作()

然而,当我到达大约9:14时,我得到了一个错误,说“期望表达式”,在else语句之前有一些标记。我现在不能发布图片,所以请把你知道的一切都发布给我。我是个新手,任何帮助都将不胜感激

我的代码(ViewController.m):


你还有两个陈述。那是不可以的

- (IBAction)NumberPressed:(UIButton*)sender;{
    NSInteger tag = sender.tag;

    if (operatorPressed == FALSE) {
        if (firstEntry == NULL) {
            firstEntry = [NSString stringWithFormat:@"%li", (long)tag];
            _OutputLabel.text = firstEntry;
        }

    }
    else {      // 1
        firstEntry = [NSString stringWithFormat:@"%@%li",firstEntry ,(long)tag];
        _OutputLabel.text = firstEntry;
    }

    else {      // 2
        if (secondEntry == NULL) {
            secondEntry = [NSString stringWithFormat:@"%li", (long)tag];
            _OutputLabel.text = secondEntry;

        }
        else {
            if secondEntry = [NSString stringWithFormat:@"%@%li",firstEntry ,(long)tag];
            _OutputLabel.text = secondEntry;

        }
    }
}

检查我用1和2标记的位置。第一个
else
应该是
else if(someCondition)
。你不能有另外两种说法

请复制您的实际代码并粘贴到您的问题中。观看其他人的视频不一定会与您的视频相匹配。如果您无法发布图像,请发布文本。。。代码是文本…它就在那里,希望您能帮助我。您在
NumberPressed
中有第二个
else
分支作为第一个
if
语句。这是无效的;每个
if
最多只能有一个
else
。即使我将第一个“else”改为“if else”,它也会显示另一条消息,“expected”(在if之后)。有什么新想法吗?@Sonicpeta你想做什么?
else if
需要一个条件,所以你会像
else if(someBoolean)一样编写它
其中
someBoolean
是一个逻辑语句,就像第一个
if
中的语句一样。请参见底部的我的编辑,我的意思是
else if
,而不是
if else
。对于增加的混乱,我深表歉意
- (IBAction)NumberPressed:(UIButton*)sender;{
    NSInteger tag = sender.tag;

    if (operatorPressed == FALSE) {
        if (firstEntry == NULL) {
            firstEntry = [NSString stringWithFormat:@"%li", (long)tag];
            _OutputLabel.text = firstEntry;
        }

    }
    else {      // 1
        firstEntry = [NSString stringWithFormat:@"%@%li",firstEntry ,(long)tag];
        _OutputLabel.text = firstEntry;
    }

    else {      // 2
        if (secondEntry == NULL) {
            secondEntry = [NSString stringWithFormat:@"%li", (long)tag];
            _OutputLabel.text = secondEntry;

        }
        else {
            if secondEntry = [NSString stringWithFormat:@"%@%li",firstEntry ,(long)tag];
            _OutputLabel.text = secondEntry;

        }
    }
}