我已经将InputAccessoryView添加到我的键盘消失。挺好的。但在一些ViewController中,它并没有出现。即使是这种方法也不会调用。
我有个按钮。当我单击该文本字段时,自动成为第一个响应程序。(当单击该按钮时,光标集中在textField上)键盘即将到来,但输入附件视图未出现。
我正在iOS 8.2设备上测试这个。这是我的密码
在viewDidload中
// for search------------------
UIView *srchPadView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];
[srchtextbox setLeftView:srchPadView];
[srchtextbox setLeftViewMode:UITextFieldViewModeAlways];
srchtextbox.attributedPlaceholder=[[NSAttributedString alloc] initWithString:alertStrings.strSearch attributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:1 green:1 blue:1 alpha:0.6]}];
[srchtextbox setTextColor:[UIColor whiteColor]];
srchtextbox.delegate=self;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(textFieldTextDidChangeOneCI:)
name:UITextFieldTextDidChangeNotification
object:srchtextbox];在textfield中更改方法
-(void)textFieldTextDidChangeOneCI:(NSNotification *)notification
{
isSearching=YES;
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(getSongs)
object:nil];
loading=YES;
[mainactivityindicator startAnimating];
songsArray=[[NSMutableArray alloc]init];
songstable.hidden=YES;
startRec=0;
[self performSelectorInBackground:@selector(getSongs) withObject:nil];
}然后
- (UIView *)inputAccessoryView {
if (!inputAccessoryView) {
CGRect accessFrame = CGRectMake(0.0, 0.0, 320, 40);
inputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
inputAccessoryView.backgroundColor = [UIColor colorWithRed:70.0/255 green:70.0/255.0 blue:70.0/255.0 alpha:0.9];
UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 1)];
[line setBackgroundColor:[UIColor colorWithRed:134.0/255.0 green:139.0/255.0 blue:143.0/255.0 alpha:1.0]];
[inputAccessoryView addSubview:line];
UIButton *compButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
compButton.frame = CGRectMake(260.0, 2, 60, 37.0);
[compButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
[compButton setTitle: @"Done" forState:UIControlStateNormal];
[compButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[compButton addTarget:self action:@selector(completeCurrentWord:)
forControlEvents:UIControlEventTouchUpInside];
[inputAccessoryView addSubview:compButton];
}
return inputAccessoryView;
}最后
-(IBAction)completeCurrentWord:(id)sender{
[self.view endEditing:YES];}
但我的inputAccessoryView从来不打电话。为什么会这样呢。我该如何解决这个问题?请帮帮我。
谢谢
发布于 2015-12-15 20:24:04
你需要
inputAccessoryView并返回视图。 -(BOOL)canBecomeFirstResponder{
return YES;
}3.当您需要输入附件视图时,请调用[self becomeFirstResponder];
提示:如果你想总是被展示出来
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self becomeFirstResponder];
}https://stackoverflow.com/questions/30164233
复制相似问题