就像标题所说的那样......我该怎么做?我希望用户输入大量文本,然后以某种方式最小化键盘并返回与该视图中的其他对象交互。但是,他们可能需要“输入”键来在键入时格式化他们的文本。有什么建议么?
Anil 建议了一个包含以下代码的链接:
(void)textViewDidBeginEditing:(UITextView *)textView {
[self createInputAccessoryView];
[textView setInputAccessoryView:_inputAccessoryView];
self.myTextView = textView; }
-(void)createInputAccessoryView {
_inputAccessoryView = [[UIToolbar alloc] init];
_inputAccessoryView.barStyle = UIBarStyleBlackOpaque;
[_inputAccessoryView sizeToFit];
_inputAccessoryView.frame = CGRectMake(0,_collageView.frame.size.height - 44, _collageView.frame.size.width, 44);
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];
[_myTextView addSubview:_inputAccessoryView];
}
但是,我在概念上有点落后……我应该把对我的 TextView、.h 或 .m 文件的引用放在哪里?没看懂怎么...
-(void)textViewDidBeginEditing:(UITextView *)textView {
...链接到我的实际文本字段。此外,xcode 为“_inputAccessoryView”抛出一个错误,说它没有在任何地方定义。非常感激你的帮助!