我有一個故事板,它有一個UITextField
,UIButton
,UIImage
和UILabel
來顯示數組中的圖像。如果您將圖像文件的正確名稱輸入到文本字段中。所以,問題是,一旦文本字段輸入不是匹配,它應該更新UILabel
顯示"Result not found"
,但它不。當我的if語句錯誤時,我的UILabel不顯示
#import "ViewController.h"
@interface ViewController()
{
myClass *myNewClass;
NSMutableArray *picArray;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
picArray = [@[@"Button_Red",@"Button_Green"]mutableCopy];
}
- (IBAction)displayImageAction:(id)sender
{
NSString *titleSearched = self.textSearchField.text;
NSString *titleNotHere = self.notFoundLabel.text;
//Declare a bool variable here and set
BOOL variable1;
for (int i = 0; i < picArray.count; i++)
{
NSString *currentPic = picArray[i];
if ([titleSearched isEqualToString:currentPic])
{
variable1 = YES;
}
}
if (variable1 == YES) {
//this works fine displays the image
self.outputImage.image = [UIImage imageNamed: titleSearched];
[self.textSearchField resignFirstResponder];
} else {
//problem is here its not showing when input for the array is not equal it should display a message label "Result Not Found" but it remains blank on the IOS simulator
titleNotHere = [NSString stringWithFormat:@"Result Not found"];
[self.textSearchField resignFirstResponder];
}
}
//Get rid of the texfield when done typing
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Retract keyboard if up
[self.textSearchField resignFirstResponder];
}
什麼是'titleNotHere'?它是設置爲某個或零? – Wain
NSString * titleNotHere = self.notFoundLabel.text;被設置爲這個希望,這有助於 – nateicon
變量1在其聲明行中設置爲FALSE。 – Larme