- (IBAction)checkBtnAction:(id)sender
{
if([answerTextFeild.text isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Enter the Caption" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
//sharedDelegate->sRow =YES;
}
else if([answerTextFeild.text isEqualToString:label.text])
{
//------ Add row number to shared array------------//
AppDelegate *sharedDelegate=(AppDelegate * )[[UIApplication sharedApplication]delegate];
sharedDelegate->sRow =YES;
[sharedDelegate.rowNumber addObject:[NSString stringWithFormat:@"%lu",(unsigned long)sharedDelegate.shareRowInteger1] ];
//------save to plist dictionary--------------//
NSString *filePath ;
if([sharedDelegate.tagValue intValue]==1)
{
NSString *filePath1 = [self dataFilePath];
filePath = filePath1;
ansDict = [[NSMutableDictionary alloc] init];
[ansDict setObject:answerTextFeild.text forKey:@"name"];
[ansDict setObject:rowNumStr forKey:@"rowNumber"];
[ansDict setObject:label.text forKey:@"tagName"];
correctImg.image = [UIImage imageNamed: @"right_ipad.png"];
chkBtn.hidden = YES;
answerTextFeild.userInteractionEnabled = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
ansArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[ansArray addObject:ansDict];
[ansArray writeToFile:filePath atomically:YES];
}
else
{
[ansArray addObject:ansDict];
[ansArray writeToFile:filePath atomically:YES];
}
}
else if([sharedDelegate.tagValue intValue]==2){
NSString *filePath2 = [self dataFilePath1];
filePath = filePath2;
ansDict1 = [[NSMutableDictionary alloc] init];
[ansDict1 setObject:answerTextFeild.text forKey:@"name"];
[ansDict1 setObject:rowNumStr1 forKey:@"rowNumber"];
[ansDict1 setObject:label.text forKey:@"tagName"];
correctImg.image = [UIImage imageNamed: @"right_ipad.png"];
chkBtn.hidden = YES;
answerTextFeild.userInteractionEnabled = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
ansArray1 = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[ansArray1 addObject:ansDict1];
[ansArray1 writeToFile:filePath atomically:YES];
}
else
{
[ansArray1 addObject:ansDict1];
[ansArray1 writeToFile:filePath atomically:YES];
}
}
else if([sharedDelegate.tagValue intValue]==3)
{
NSString *filePath3 = [self dataFilePath2];
filePath = filePath3;
ansDict2 = [[NSMutableDictionary alloc] init];
[ansDict2 setObject:answerTextFeild.text forKey:@"name"];
[ansDict2 setObject:rowNumStr2 forKey:@"rowNumber"];
[ansDict2 setObject:label.text forKey:@"tagName"];
correctImg.image = [UIImage imageNamed: @"right_ipad.png"];
chkBtn.hidden = YES;
answerTextFeild.userInteractionEnabled = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
ansArray2 = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[ansArray2 addObject:ansDict2];
[ansArray2 writeToFile:filePath atomically:YES];
}
else
{
[ansArray2 addObject:ansDict2];
[ansArray2 writeToFile:filePath atomically:YES];
}
}
else if([sharedDelegate.tagValue intValue]==4){
NSString *filePath4 = [self dataFilePath3];
filePath = filePath4;
ansDict3 = [[NSMutableDictionary alloc] init];
[ansDict3 setObject:answerTextFeild.text forKey:@"name"];
[ansDict3 setObject:rowNumStr3 forKey:@"rowNumber"];
[ansDict3 setObject:label.text forKey:@"tagName"];
correctImg.image = [UIImage imageNamed: @"right_ipad.png"];
chkBtn.hidden = YES;
answerTextFeild.userInteractionEnabled = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
ansArray3 = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[ansArray3 addObject:ansDict3];
[ansArray3 writeToFile:filePath atomically:YES];
}
else
{
[ansArray3 addObject:ansDict3];
[ansArray3 writeToFile:filePath atomically:YES];
}
}
else if([sharedDelegate.tagValue intValue]==5)
{
NSString *filePath5 = [self dataFilePath4];
filePath = filePath5;
ansDict4 = [[NSMutableDictionary alloc] init];
[ansDict4 setObject:answerTextFeild.text forKey:@"name"];
[ansDict4 setObject:rowNumStr4 forKey:@"rowNumber"];
[ansDict4 setObject:label.text forKey:@"tagName"];
correctImg.image = [UIImage imageNamed: @"right_ipad.png"];
chkBtn.hidden = YES;
answerTextFeild.userInteractionEnabled = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
ansArray4 = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[ansArray4 addObject:ansDict4];
[ansArray4 writeToFile:filePath atomically:YES];
}
else
{
[ansArray4 addObject:ansDict4];
[ansArray4 writeToFile:filePath atomically:YES];
}
}
else if([sharedDelegate.tagValue intValue]==6)
{
NSString *filePath6 = [self dataFilePath5];
filePath = filePath6;
ansDict5 = [[NSMutableDictionary alloc] init];
[ansDict5 setObject:answerTextFeild.text forKey:@"name"];
[ansDict5 setObject:rowNumStr5 forKey:@"rowNumber"];
[ansDict5 setObject:label.text forKey:@"tagName"];
correctImg.image = [UIImage imageNamed: @"right_ipad.png"];
chkBtn.hidden = YES;
answerTextFeild.userInteractionEnabled = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
ansArray5 = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[ansArray5 addObject:ansDict5];
[ansArray5 writeToFile:filePath atomically:YES];
}
else
{
[ansArray5 addObject:ansDict5];
[ansArray5 writeToFile:filePath atomically:YES];
}
}
// ---if answer is correct disply alert to user----//
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Congratulations" message:@"Correct Answer" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
[self.navigationController popViewControllerAnimated:YES];
//------ Notify the correct answer to required view ----//
NSString *StrAnswerCorrectImg = @"CorrectImage";
if ([StrAnswerCorrectImgobj isEqualToString:StrAnswerCorrectImg])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"CorrectImage" object:nil];
}
sharedDelegate->sRow =YES;
}
else if(![answerTextFeild.text isEqualToString:label.text])
{
self.navigationItem.rightBarButtonItem = dismissKeyboardButton;
AppDelegate *sharedDelegate=(AppDelegate * )[[UIApplication sharedApplication]delegate];
NSUInteger approximateInt = sharedDelegate.shareRowInteger1;
[ sharedDelegate.rowNumberApproximate addObject:[NSString stringWithFormat:@"%lu",(unsigned long)approximateInt] ];
if ([label.text rangeOfString:answerTextFeild.text].location != NSNotFound) {
correctImg.image = [UIImage imageNamed: @"approximately.png"];
NSRange r = [label.text rangeOfString:answerTextFeild.text];
float portion = (float)r.length / (float)[label.text length];
NSString *floatrs = [NSString stringWithFormat:@" %.1f%",(portion *100)];
percentageLbl.text = floatrs;
NSString *StrAnswerApproximateImg = @"ApproximateImage";
if ([StrAnswerapproximateImgobj isEqualToString:StrAnswerApproximateImg])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ApproximateImage" object:nil];
}
}
else
{
correctImg.image = [UIImage imageNamed: @"wrong_ipad.png"];
NSString *StrAnswerSaveImg = @"wrongImage";
AppDelegate *sharedDelegate=(AppDelegate * )[[UIApplication sharedApplication]delegate];
[ sharedDelegate.rowNumberWrong addObject:[NSString stringWithFormat:@"%lu",(unsigned long)sharedDelegate.shareRowInteger1] ];
if ([StrAnswerSaveImgobj isEqualToString:StrAnswerSaveImg])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"wrongImage" object:nil];
sharedDelegate->sRow =YES;
}
}
}
}
Here, else if([answerTextFeild.text isEqualToString:label.text]) is not working and another all statements are working. This is the only statement that is not working. When debbuging the code not it does not enter this if([answerTextFeild.text isEqualToString:label.text]).
Aucun commentaire:
Enregistrer un commentaire