Iphone 使用文本字段的Xcode应更改字符范围:应用程序崩溃
我正在尝试使用我在此处找到的脚本在文本字段下实现自动完成功能: 但是它按它应该的方式运行脚本,然后应用程序崩溃而没有给我一个理由(只是在TUAppDelegate中执行坏访问) 不,我有一些其他的键盘方法,所以不知道它们是否冲突 textfield声明如下:Iphone 使用文本字段的Xcode应更改字符范围:应用程序崩溃,iphone,ios,objective-c,Iphone,Ios,Objective C,我正在尝试使用我在此处找到的脚本在文本字段下实现自动完成功能: 但是它按它应该的方式运行脚本,然后应用程序崩溃而没有给我一个理由(只是在TUAppDelegate中执行坏访问) 不,我有一些其他的键盘方法,所以不知道它们是否冲突 textfield声明如下: mytextfield_textfield = [[UITextField alloc] initWithFrame:CGRectMake(60, 57, 145, 20)]; mytextfield_textfield.borderSt
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];
然后下面的autocompleteview作为滚动视图而不是tableview(另一个原因)。但它现在没有被使用
那么我已经有了这些方法:
- (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返回OK,但随后崩溃。知道为什么吗
我只是在做NSLog,因为我想弄清楚为什么它不起作用
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return YES;
}
因为我不知道的原因,[词典发布]才是罪魁祸首。谁能解释为什么?同样的事情让我在应用程序的另一个部分崩溃了,我还发布了一本从plist读取的词典。
注释它解决了所有问题,即使我在for循环后不使用字典添加AddAction:method的代码粘贴从主捆绑包中读取的字典内容。哦,是的,我已经设置了:o)我在dispair中尝试了这两种方法,但意外地复制粘贴了表示不的内容:-)