gpt4 book ai didi

iphone - Xcode 使用 textField shouldChangeCharactersInRange : crashes app

转载 作者:行者123 更新时间:2023-11-29 04:22:31 26 4
gpt4 key购买 nike

我正在尝试使用我在这里找到的脚本在文本字段下实现自动完成功能:

http://www.raywenderlich.com/336/how-to-auto-complete-with-custom-values

但它按应有的方式运行脚本,然后应用程序崩溃了,没有给我任何反应(只是 TUAppDelegate 中的 exc_bad_access )

不,我还有其他一些键盘方法,所以不知道它们是否冲突。

文本字段声明如下:

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];

然后下面的自动完成 View 作为 ScrollView 而不是表格 View (另一个原因)。但现在还没有使用。

那么我已经有了这些方法:

- (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] ;
}

它输出 key 并从 NSlog 返回 OK,但随后崩溃了。知道为什么吗?

我只是做 NSLog,因为我想弄清楚为什么它不起作用

最佳答案

改变

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

return YES;
}

关于iphone - Xcode 使用 textField shouldChangeCharactersInRange : crashes app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12793087/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com