내가 내가 여기 스크립트를 사용하여 텍스트 필드에서 자동 완성 funktion을 구현하기 위해 노력하고있어 충돌 :엑스 코드는 : 응용 프로그램
http://www.raywenderlich.com/336/how-to-auto-complete-with-custom-values
을하지만 다음 스크립트 예상대로 실행하고, 응용 프로그램이 내게 공명을주지 않고 충돌합니다 (TUAppDelegate의 exc_bad_access 만 해당).
아니요. 다른 몇 가지 키보드 기능이 없으므로 충돌이 있는지 모릅니다. 대신 tableview에 (즉, 또 다른 이유)에있는 ScrollView로 autocompleteview 아래 다음
mytextfield_textfield = [[UITextField alloc] initWithFrame:CGRectMake(60, 57, 145, 20)];
mytextfield_textfield.borderStyle = UITextBorderStyleNone;
mytextfield_textfield.font = [UIFont fontWithName:@"NeoSans" size:14];
mytextfield_textfield.placeholder = @"Enter something";
mytextfield_textfield.text = @"";
mytextfield_textfield.secureTextEntry = NO;
mytextfield_textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
mytextfield_textfield.autocorrectionType = UITextAutocorrectionTypeNo;
mytextfield_textfield.keyboardType = UIKeyboardTypeDefault;
mytextfield_textfield.returnKeyType = UIReturnKeyDone;
mytextfield_textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
mytextfield_textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
mytextfield_textfield.delegate = self;
[self.view addSubview:mytextfield_textfield];
하고 :
텍스트 필드는 다음과 같이 선언된다. 하지만 지금은 사용되지 않습니다.
그때 나는 이미 이러한 방법이 있습니다
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
if(touch.phase == UITouchPhaseBegan) {
[mytextfield_textfield resignFirstResponder];
}
[mytextfield_textfield resignFirstResponder];
myTableView.userInteractionEnabled = YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
myTableView.userInteractionEnabled = NO;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[mytextfield_textfield resignFirstResponder];
myTableView.userInteractionEnabled = YES;
[self performSelector:@selector(AddAction:) withObject:nil] ;
return YES;
}
을 그리고 지금은 자동 완성 구현 :
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
autocompleteView.hidden = NO;
NSString *substring = [NSString stringWithString:textField.text];
substring = [substring stringByReplacingCharactersInRange:range withString:string];
[self searchAutocompleteEntriesWithSubstring:substring];
myTableView.userInteractionEnabled = YES;
NSLog(@"ok") ;
return NO;
}
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
NSDictionary *dictionary = [[NSDictionary alloc] init ];
NSString *path = [[NSBundle mainBundle] bundlePath] ;
NSString *dictionary_path = [path stringByAppendingPathComponent:@"categorieslist2.plist"] ;
dictionary = [NSDictionary dictionaryWithContentsOfFile:dictionary_path] ;
for(id key in dictionary) {
NSLog(@"%@",key) ;
}
[dictionary release] ;
}
그것은 출력의 열쇠를하고 NSlog에서 확인을 반환하지만 그것은 충돌합니다. 왜 그런가? 그 이유
AddAction 코드 추가 : –
메인 번들에서 읽은 사전 내용을 붙여 넣습니다. –