iOS:用户在 TextView (xcode) 中键入后无法最小化键盘 [英] iOS: Can't minimize the keyboard after user types in TextView (xcode)

查看:18
本文介绍了iOS:用户在 TextView (xcode) 中键入后无法最小化键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个用户向我提供了以下代码,以便在用户输入特定 TextView 时在键盘上方创建一个迷你工具栏.我所需要的只是一个小的关闭"按钮,用于在用户完成后最小化键盘,以便他/她可以继续操作应用程序.

Another user provided me with the following code in order to make a mini toolbar above the keyboard when a user is typing in a specific TextView. All I need is a little "close" button to minimize the keyboard when the user is finished, so he/she can continue manipulating the app.

-(void)viewDidLoad
{
[super viewDidLoad]
UIToolbar *inputAccessoryView = [[UIToolbar alloc]init]; // Create one input accessory view, tool bar will be easy for you  
inputAccessoryView.frame = CGRectMake(0,self.view.frame.size.height - 44, self.view.frame.size.width, 44);

// Add required buttons
UIBarButtonItem *fontItem = [[UIBarButtonItem alloc] initWithTitle:@"Font"
                                                             style:UIBarButtonItemStyleBordered
                                                            target:self action:@selector(changeFont:)];
UIBarButtonItem *removeItem = [[UIBarButtonItem alloc] initWithTitle:@"Remove"
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self action:@selector(removeTextView:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                          target:nil
                                                                          action:nil];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                             style:UIBarButtonItemStyleDone
                                                            target:self action:@selector(dismissKeyBoard:)];

NSArray *items = [NSArray arrayWithObjects:fontItem,removeItem,flexItem,doneItem, nil];
[inputAccessoryView setItems:items animated:YES];

//You should create an outlet for the text view before doing this 
[self.questionsTextView setInputAccessoryView:inputAccessoryView];

}

但是,只要按下关闭"按钮,应用就会崩溃.我不确定我是否正确地遵循了方向:我应该为 TextView 制作一个出口,所以我将输出输出到 viewController 的头文件并将其命名为 questionsTextView.然后我将它合成到我的 .m 文件中,并将实例命名为 _questionsTextView.

However, the app crashes whenever the "close" button is pressed. I'm not sure if I am following the direction correctly: I am supposed to make an outlet for the TextView, so I made the output to the viewController's header file and named it questionsTextView. Then I synthesized it in my .m file, and named the instance _questionsTextView.

谁能帮我一把?我是 xcode 的新手,正在慢慢掌握 Objective-c 的窍门!谢谢.

Can anyone please give me hand? I'm brand-new to xcode and am slowly getting the hang of objective-c! Thanks.

推荐答案

您提供的错误消息表明您的方法存在问题.

the error message you supplied suggest there something wrong with your methods.

@selector(changeFont:)]
@selector(removeTextView:)];
@selector(dismissKeyBoard:)];

仔细检查所有三个方法都接受一个参数:符号指定它应该,并检查你的方法拼写.

double check the all three methods take a parameter as : symbol specify it should, and also check your method spelling.

验证对象可以响应方法:

verify object can respond to method:

NSLog(@"Method 确实响应了: %d", [self RespondsToSelector:@selector(aMethod)]);

NSLog(@"Method does respond: %d", [self respondsToSelector:@selector(aMethod)]);

这篇关于iOS:用户在 TextView (xcode) 中键入后无法最小化键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆