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