2012-10-09 4 views
0

내가 내가 여기 스크립트를 사용하여 텍스트 필드에서 자동 완성 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에서 확인을 반환하지만 그것은 충돌합니다. 왜 그런가? 그 이유

+1

AddAction 코드 추가 : –

+0

메인 번들에서 읽은 사전 내용을 붙여 넣습니다. –

답변

1

변화

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 

return YES; 
} 
+0

무엇으로 변경하나요? –

+0

예 아니오로 돌아 가기 – Venkat

+0

오, 그래, 나는 그것을 설정했다 : o) 나는 dispair에서 둘 다 시도해 보았고 실수로 아무 말도하지 않는 것을 붙여 넣었다 :-) –

0

작업 밤은 왜 내가 전혀 생각의 [사전 릴리스] 없습니다 알아 내려고 시도하고 있기 때문에 난 그냥 만 NSLog를하고 있어요

범인이었다. 왜 아무도 설명 할 수 없나요? 같은 일이 나에게 plist에서 읽은 사전을 발표 한 앱의 다른 섹션에서 충돌을 주었다. for 루프 이후에 사전을 사용하지 않더라도 모든 것을 해결하는 주석 처리

관련 문제