您可能知道我对iOS开发非常陌生并且有一个非常具体的问题。我需要编写一个if ... else
语句,在if中有四个条件,然后才会执行实际操作。所以我需要做这样的事情:
如果(条件1 +条件2 +条件3 +条件4) 然后 {实际行动} 其他 .....................
当我尝试
时-(IBAction)Buttontouched: (id) sender;
{
if (NSOrderedSame == [self.InputField1.text caseInsensitiveCompare:@"teacher"]){
if (NSOrderedSame == [self.InputField2.text caseInsensitiveCompare:@"Maths"]){
if (NSOrderedSame == [self.InputField3.text caseInsensitiveCompare:@"english"]){
if (NSOrderedSame == [self.InputField4.text caseInsensitiveCompare:@"greek"]){
NumberCount = NumberCount +5;
ErrorLabel.text = [NSString stringWithFormat:@"You have achived %i out of 50 points", >NumberCount];
April1.hidden = true;
}
}
}
}
}
它不起作用......请帮助我!
答案 0 :(得分:3)
您可以这样做,只有在所有4个陈述都为真的情况下才会继续。
-(IBAction)Buttontouched: (id) sender {
if ((NSOrderedSame == [self.InputField1.text caseInsensitiveCompare:@"teacher"]) &&
(NSOrderedSame == [self.InputField2.text caseInsensitiveCompare:@"Maths"]) &&
(NSOrderedSame == [self.InputField3.text caseInsensitiveCompare:@"english"]) &&
(NSOrderedSame == [self.InputField4.text caseInsensitiveCompare:@"greek"]))
{
NumberCount = NumberCount +5;
ErrorLabel.text = [NSString stringWithFormat:@"You have achived %i out of 50 points", >NumberCount];
April1.hidden = true;
} else {
}
}
答案 1 :(得分:0)
if ((NSOrderedSame == [self.InputField1.text caseInsensitiveCompare:@"teacher"])&&(NSOrderedSame == [self.InputField2.text caseInsensitiveCompare:@"Maths"])&&(NSOrderedSame == [self.InputField3.text caseInsensitiveCompare:@"english"])&&(NSOrderedSame == [self.InputField4.text caseInsensitiveCompare:@"greek"]))
{
// your code here
}
else
{
//another code here
}