【发布时间】:2016-04-16 16:54:58
【问题描述】:
在我的项目中,一些视图控制器有多个文本字段,
我找到了如何在键盘上方添加一个带有“确定”按钮的工具栏,以便在点击按钮时隐藏键盘。
我使用的代码如下:
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:_destField action:@selector(resignFirstResponder)];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 34)];
toolbar.items = [NSArray arrayWithObjects:flex, barButton, nil];
_destField.inputAccessoryView = toolbar;
如何在同一个视图控制器中轻松重用此代码?
“目标”使这变得困难,有没有办法不为每个文本字段创建工具栏?
谢谢!
【问题讨论】:
标签: ios objective-c uitextfield uitoolbar