这段代码没有错误,但是当我点击按钮时,“if”语句中没有任何内容 作品!它不会崩溃或显示错误...顺便说一句,我正在使用 Xcode 开发 iphone 应用程序。
#import "MainView.h"
@implementation MainView
@synthesize MyButton2, MyMainTextLabel;
@synthesize MyButton3, MyMainTextLabel;
@synthesize MyButton2, Button2Label;
@synthesize MyButton2, Button3Label;
@synthesize MyButton3, Button2Label;
@synthesize MyButton3, Button3Label;
- (IBAction)Button2click {
if(Button2Label.text == @"Hello There!") {
MyMainTextLabel.text = @"\"Hey...!!\"";
Button3Label.text = @"What a rude Penguin!";
Button2Label.text = @"Hows a Goin?";
}
}
- (IBAction)Button3click {
if(Button3Label.text == @"Penguins SUCK!") {
MyMainTextLabel.text = @"\"DONT TEST ME!!\"";
Button3Label.text = @"Oh I Will!";
Button2Label.text = @"Sorry I didnt mean to...";
}
}
- (IBAction)buttonclick {
}
@end
最佳答案
您不能将字符串与 ==
进行比较。仅当它们是完全相同的 NSString 对象时才有效,如果它们是两个相同的字符串则无效。使用 [buttonLabel.text isEqualToString:@"Hello There!"]
关于objective-c - if else 语句不起作用!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1094031/