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