当我点击文本字段时,textFieldDidBeginEditing在第二次点击后开始被触发。当我删除下面的代码并在textFieldDidBeginEditing方法之后。它是在第一次点击时被解雇的。如何在第一次点击时将其解雇?
[numKeyboard.view setFrame:CGRectMake(0, self.view.frame.size.height-numKeyboard.view.frame.size.height,320, 320)];
.m文件:
#import "MainViewController.h"
#import "HastaDAO.h"
#import "YatanHastaBilgileriDAO.h"
#import "SettingViewController.h"
#import "Global.h"
#import <AudioToolbox/AudioServices.h>
#import "AlerjiModel.h"
#import "AlerjiDAO.h"
#import "NumKeyboard.h"
@interface MainViewController ()
{
int whichbtn;
}
@end
@implementation MainViewController
@synthesize player=_player;
@synthesize resultText1, resultText2,result,closeResult;
NSMutableArray *favTani;
HastaModel *yatanHastaBilgisi;
NSString *currentKey,*sound;
NSString *currentStringValue;
HastaModel *hasta;
int compareResult;
NSString *string=@"";
NSInteger didCompare=1;
UIImage *img;
NSString *str1,*str2;
NSInteger fromHistory=0;
-(void)viewDidAppear:(BOOL)animated{
if(fromHistory){
self.resultText1.text=str1;
self.resultText2.text=str2;
}
}
+(void)set_from_view:(NSInteger)history scanner:(NSInteger)scanner{
fromHistory=history;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (textField == self.resultText2 && (![self.resultText1.text isEqualToString:@""] && ![self.resultText2.text isEqualToString:@""])){
[self destroyNumKeyboard];
[self compareTwoBarcode];
}
}
+(void)setResultTexts:(NSString*)str img:(UIImage*)image{
string=str;
img=[[UIImage alloc]init];
img=image;
}
-(void)compareTwoBarcode{
[self.resultText1 resignFirstResponder];
[self.resultText2 resignFirstResponder];
if(![self.resultText1.text isEqualToString:@""] && ![self.resultText2.text isEqualToString:@""] )
{
didCompare=1;
if ([resultText1.text isEqualToString:resultText2.text]) {
sound=@"%@/accept.mp3";
result.text = @"EŞLEŞİYOR";
result.backgroundColor = [UIColor colorWithRed:153/255.0 green:255/255.0 blue:51/255.0 alpha:0.85];
compareResult=1;
}
else
{
sound=@"%@/reject.mp3";
result.text = @"EŞLEŞMİYOR";
result.backgroundColor = [UIColor colorWithRed:255/255.0 green:0/255.0 blue:0/255.0 alpha:0.85];
compareResult=0;
}
[closeResult setHidden:FALSE];
[result setHidden:FALSE];
NSString *soundFilePath = [NSString stringWithFormat:sound, [[NSBundle mainBundle] resourcePath]];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1; //Infinite
if([SettingViewController getVolume])
[player play];
if([SettingViewController getVibrate]){
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uyarı"
message:@"Barkod alanları dolu olmalıdır!"
delegate:nil
cancelButtonTitle:@"Tamam"
otherButtonTitles:nil];
[alert show];
}
}
-(void)setHistorySource{
NSString *word= self.resultText1.text;
NSString *pathhistory = [[self documentsDirectory] stringByAppendingPathComponent:@"history.plist"];
NSMutableArray *histList = [[NSMutableArray alloc] initWithContentsOfFile:pathhistory];
NSInteger ishist=0;
for (NSInteger i=[histList count]-1; i>=0;i--) {
NSDictionary *d = [histList objectAtIndex:i];
//NSString *patientName=[d objectForKey:@"PATIENT"];
NSString *name1=[d objectForKey:@"WORD1"];
NSString *name2=[d objectForKey:@"WORD2"];
if([name1 isEqualToString:self.resultText1.text] &&
[name2 isEqualToString:self.resultText2.text])
ishist=1;
}
if(ishist==0){
HastaModel*hmodel=[[HastaModel alloc]init];
NSMutableArray *arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:1];
if([arr count]==0)
arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:0];
if([arr count]){
hmodel=[arr objectAtIndex:0];
NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:
hmodel.Ad, @"PATIENT",
self.resultText1.text, @"WORD1",
self.resultText2.text,@"WORD2",
[NSString stringWithFormat:@"%ld",(long)compareResult ],@"EQUAL",
nil];
[histList addObject:dic];
if(![word isEqual:@""])
[histList writeToFile:pathhistory atomically:TRUE];
}
}
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation{
return(YES);
}
+(void)setbarcode1:(NSString*)barcode1 barcode2:(NSString*)barcode2{
str1=barcode1;
str2=barcode2;
}
- (void)viewDidLoad{
[super viewDidLoad];
[self.resultText1 setDelegate:self];
[self.resultText2 setDelegate:self];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return true;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
//if(textField==self.resultText2 && !resultText2.isFirstResponder){
UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
textField.inputView = dummyView;
int i=0;
for(UIViewController *vc in self.childViewControllers)
if([vc isKindOfClass:[NumKeyboard class]])
{
i++;
break;
}
if(!i){
NumKeyboard* numKeyboard = [[NumKeyboard alloc] initWithNibName:@"NumKeyboard" bundle:nil];
[numKeyboard.view setFrame:CGRectMake(0, self.view.frame.size.height-numKeyboard.view.frame.size.height, 320, 320)];
[self.view addSubview:numKeyboard.view];
[self addChildViewController:numKeyboard];
}
[self.view reloadInputViews];
//}
}
-(void)destroyNumKeyboard {
for(UIViewController *vc in self.childViewControllers){
if([vc isKindOfClass:[NumKeyboard class]])
{
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
[self.parentViewController reloadInputViews];
}
break;
}
/*for (NumKeyboard *numKeyboardView in self.childViewControllers) {
if(numKeyboardView){
//UIButton son obje olduğu için
//[self.view.subviews.lastObject removeFromSuperview];
for (UIButton * btn in self.view.subviews) {
if([btn isKindOfClass:[UIButton class]])
if([btn.titleLabel.text isEqualToString:@"X"]){
[btn removeFromSuperview];
break;
}
}
[numKeyboardView willMoveToParentViewController:nil];
[numKeyboardView.view removeFromSuperview];
[numKeyboardView removeFromParentViewController];
[self reloadInputViews];
break;
}
}*/
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
-(void) closeHastaDetail{
[self.hastadetailview setHidden:TRUE];
}
-(void) closeHastaDetailDetail{
[self.hastadetailindetailview setHidden:TRUE];
}
-(void) openHastaDetailDetail{
[self.hastadetailindetailview setHidden:FALSE];
}
/*
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if(textField.tag==2){
NSCharacterSet* numberCharSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
for (int i = 0; i < [string length]; ++i)
{
unichar c = [string characterAtIndex:i];
if (![numberCharSet characterIsMember:c])
{
return NO;
}
}
}
return YES;
}*/
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
currentKey=elementName;
currentStringValue=nil;
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
if(tabBar.tag == 0)
{
[self closeHastaDetail];
[self closeHastaDetailDetail];
}
}
- (NSString *)documentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject];
}
+(void)setDidCompareZero{
didCompare=0;
}
- (IBAction)closehastadetail:(id)sender {
[self.hastadetailview setHidden:TRUE];
[self performSelector:@selector(setHistorySource) withObject:nil afterDelay:0.1f];
}
- (IBAction)push_CompareBtn:(id)sender {
[self compareTwoBarcode];
}
- (IBAction) closeResult:(id)sender{
[closeResult setHidden:TRUE];
[result setHidden:YES];
if([SettingViewController getTekliCokluArama]==1){
}
}
- (IBAction)del_txt1:(id)sender {
self.resultText1.text=@"";
}
- (IBAction)del_txt2:(id)sender {
self.resultText2.text=@"";
}
- (IBAction) deleteResult:(id)sender{
//[resultImage1 setImage: [UIImage imageNamed:@"img1.png"]];
resultText1.text = @"";
//[resultImage2 setImage:[UIImage imageNamed:@"img2.png"]];
resultText2.text = @"";
}
- (IBAction) okDetailBtn:(id)sender{
[self.hastadetailindetailview setHidden:TRUE];
}
- (IBAction) showDetail:(id)sender{
[MainViewController set_from_view:0 scanner:0];
[self openHastaDetailDetail];
}
- (IBAction)setHastaDetail:(id)sender {
[self closeHastaDetailDetail];
self.hastadetailview.contentSize =CGSizeMake(320, 600);
[self.hastadetailview setContentOffset:CGPointMake(self.hastadetailview.contentOffset.x, 0)
animated:YES];
if(hasta==nil)
hasta=[[HastaModel alloc]init];
if([self.resultText1.text length]>0){
NSMutableArray *arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:1];
if(![arr count] && ![self.resultText1.text isEqualToString:self.hastaProtokol.text])
arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:0];
if([arr count])
{
hasta =[arr objectAtIndex:0];
if(![self.resultText1.text isEqualToString:self.hastaProtokol.text])
yatanHastaBilgisi=[YatanHastaBilgileriDAO yatanHastaBilgileri:hasta.Id];
self.hastaAd.text=hasta.Ad;
self.hastaAd.textAlignment=NSTextAlignmentRight;
self.hastaAd.font=[UIFont systemFontOfSize:18];
self.hastaProtokol.text=[NSString stringWithFormat:@"%ld", (long)hasta.Id];
self.hastaBolum.text=hasta.Bolum;
self.hastaOda.text=hasta.Oda;
self.hastaCinsiyet.text=hasta.Cinsiyet;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSString *strDate = [dateFormatter stringFromDate:yatanHastaBilgisi.DogumTarihi];
self.hastaDogumTarihi.text=strDate;
self.hastaYatak.text=hasta.Yatak;
self.hastaDoktor.text=yatanHastaBilgisi.Doktor;
if(hasta.LastOrderId>0)
{
NSMutableArray *arr1= [AlerjiDAO alerji:0 orderId:hasta.LastOrderId];
NSString*hAlerji=@"";
for(AlerjiModel *item in arr1 )
{
if(![hAlerji isEqualToString:@""])
hAlerji=[NSString stringWithFormat:@"%@,%@",hAlerji,item.Ad];
else
hAlerji=item.Ad;
}
self.hastaAlerji.text = hAlerji;
}else
self.hastaAlerji.text =@"";
[self.hastadetailview setHidden:FALSE];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"Hasta bulunamadı."
delegate:nil
cancelButtonTitle:@"Tamam"
otherButtonTitles:nil];
[alert show];
}
}
}@end