有很多类似于我的帖子,但给出的答案对我的程序不起作用。我已经读了很多论坛和博客。我真的很难,请帮帮我。我的程序有一个由用户输入的字符串,如果它相同或不相同,它会将其与数组进行比较。
代码:
IBOutlet UILabel *aScreen;
IBOutlet UILabel *result;
NSMutableArray *b = [[NSMutableArray alloc]init];
[b addObject: @"one"];
[b addObject: @"two"];
[b addObject: @"rawr"];
if([b containsObject:aScreen]){
result = [NSString stringWithFormat:@"TRUE"];
} //this is my first trial.. there are no errors but it does not work the way I want it.
它应该将aScreen中的字符串与数组b进行比较,如果"result"中的字符串相等,则输出"true"。如果我要输入"one=1",那么"结果"应该显示为"true"。
您将字符串分配给标签,但应该使用其text
属性。执行以下操作:
if ([b containsObject: aScreen.text]) {
result.text = @"TRUE";
}