.numberPad键盘上没有"完成"按钮.当用户在文本字段中输入完数字信息后,如何使数字键盘消失?

我可以通过使用默认键盘获得"完成"按钮,但用户必须切换到数字键才能输入数字.有没有办法在数字键盘上显示"完成"按钮?

推荐答案

Another solution. Perfect if there are other non-number pad text fields on the screen.

inputAccessoryView

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    numberToolbar.barStyle = UIBarStyleBlackTranslucent;
    numberToolbar.items = @[[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
                         [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                         [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)]];
    [numberToolbar sizeToFit];
    numberTextField.inputAccessoryView = numberToolbar;
}

-(void)cancelNumberPad{
    [numberTextField resignFirstResponder];
    numberTextField.text = @"";
}

-(void)doneWithNumberPad{
    NSString *numberFromTheKeyboard = numberTextField.text;
    [numberTextField resignFirstResponder];
}

Ios相关问答推荐

SwiftUI中ForEach和@ State数组的可能并发问题

Jenkins node 无法运行fastlane命令-未找到命令

在某些情况下,UIHostingController在自动调整时不能调整大小

Swift在SceneKit中为scnnode添加自定义几何体(视图)

如何在SwiftUI中为带有CornerRadius的矩形创建下边框?

AVAudioRecord 没有音频

查找东南亚语言(泰语、高棉语、老挝语、缅甸语)中的单词边界

滚动 swiftUI 列表时,未调用单元格的任务修饰符.怎么修?

iOS按钮和navigationLink在List中相邻

UIViewRepresentable - MKMapView 没有得到更新

滑动以返回特定的 SwiftUI 视图

如何从 scendelegate 打开我的标签栏控制器

是否可以在没有 Mac 的情况下为 iOS 制作 PhoneGap 应用程序?

Got Unrecognized selector -replacementObjectForKeyedArchiver: 在 Swift 中实现 NSCoding 时崩溃

获取 iOS 上所有联系人的列表

通过 segue 传递数据

iOS 应用程序中的手动语言 Select (iPhone 和 iPad)

swift 语言中的 null / nil

iOS7 UITextView contentsize.height 替代

具有两种不同字体大小的 NSAttributedString 示例?