UITextField 自定义输入

UITextField custom input

我创建了一个有自己键盘的应用程序。需要键盘(必须是唯一的输入源)将数字输入两个文本字段,如图所示:

软键盘在我的应用程序中出现如下:

我不希望在用户按下任何文本字段时出现软键盘。以下是我的代码:

对于ViewController.h

    @interface ViewController : UIViewController<UITextFieldDelegate, GADBannerViewDelegate> {

    IBOutlet UITextField *fixedPrice;
    IBOutlet UITextField *discountRate;
    IBOutlet UITextField *savedPrice;
    IBOutlet UITextField *finalPrice;
    IBOutlet UIStackView *customKeyboard;

}

@property(nonatomic, weak) IBOutlet GADBannerView *bannerView;

-(IBAction)dotButtonPressed;
-(IBAction)digitButtonPressed:(id)sender;
-(IBAction)zeroButtonPressed;
-(IBAction)backspaceButtonPressed;

-(IBAction)calculatePressed;
-(IBAction)clearAll;

@property (nonatomic, retain) IBOutlet UITextField *fixedPrice;
@property (nonatomic, retain) IBOutlet UITextField *discountRate;
@property (weak, nonatomic) IBOutlet UIStackView *customKeyboard;

@end

对于ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize fixedPrice;
@synthesize discountRate;

- (void)viewDidLoad {
    fixedPrice.delegate = self;
    discountRate.delegate = self;
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    fixedPrice.inputView = self.customKeyboard;
    discountRate.inputView = self.customKeyboard;

    //fixedPrice.inputAccessoryView = _customKeyboard;
    //discountRate.inputAccessoryView = _customKeyboard;

    [fixedPrice becomeFirstResponder];
}

下图显示了与插座的连接:

在我的 ViewController.m 中,我收到以下警告(我不确定是否相关):

考虑到以上情况,键盘仍然出现。有什么想法吗?

编辑(崩溃日志):

2018-03-12 21:00:58.966215+0300 Diskon[261:8180] [DYMTLInitPlatform] platform initialization successful
2018-03-12 21:00:59.241857+0300 Diskon[261:8089] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-03-12 21:00:59.242550+0300 Diskon[261:8089] [MC] Reading from public effective user settings.
2018-03-12 21:00:59.371628+0300 Diskon[261:8089] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-03-12 21:00:59.374741+0300 Diskon[261:8089] [MC] Loaded MobileCoreServices.framework
2018-03-12 21:00:59.497213+0300 Diskon[261:8172] 4.8.1 - [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40009000 started
2018-03-12 21:00:59.497706+0300 Diskon[261:8172] 4.8.1 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled 
2018-03-12 21:00:59.812086+0300 Diskon[261:8172] <Google> Advertising tracking may be disabled. To get test ads on this device, enable advertising tracking.
2018-03-12 21:00:59.837680+0300 Diskon[261:8089] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x107526090 V:[GADBannerView:0x1019fa3b0]-(5)-[UILabel:0x107521d90'%']   (active)>",
    "<NSLayoutConstraint:0x1075261e0 UILabel:0x107521d90'%'.centerY == UILabel:0x107520070'Kalkulator Diskon'.centerY   (active)>",
    "<NSLayoutConstraint:0x107526400 UILabel:0x107521d90'%'.lastBaseline == UILabel:0x107520070'Kalkulator Diskon'.lastBaseline   (active)>",
    "<NSLayoutConstraint:0x1075266a0 V:[GADBannerView:0x1019fa3b0]-(5)-[UILabel:0x107520070'Kalkulator Diskon']   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x107526090 V:[GADBannerView:0x1019fa3b0]-(5)-[UILabel:0x107521d90'%']   (active)>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
    2018-03-12 21:00:59.978231+0300 Diskon[261:8089] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x107555f20> should have parent view controller:<ViewController: 0x101877a00> but requested parent is:<UIInputWindowController: 0x102874400>'
    *** First throw call stack:
    (0x181173164 0x1803bc528 0x1811730ac 0x18a7c2804 0x18b2f74bc 0x18b2f85a0 0x18a73b92c 0x18b2f82fc 0x18b2f025c 0x18a7e1eec 0x18a753994 0x18a752fbc 0x18aaef974 0x18b3a124c 0x18a7ad8c4 0x18a98dc7c 0x18a992a14 0x18ac2e2a8 0x18af06100 0x18ac2df0c 0x18ac2e76c 0x18b3b37c0 0x18b3b3664 0x18b1212cc 0x18b2ba3cc 0x18b12117c 0x18af05760 0x18a991158 0x18ada6dbc 0x1838361f0 0x18383eaf8 0x100d1928c 0x100d259e4 0x18386a7f8 0x18386a49c 0x18386aa38 0x18111b77c 0x18111b6fc 0x18111af84 0x181118b5c 0x181038c58 0x182ee4f84 0x18a7915c4 0x1009309d4 0x180b5856c)
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 

根据您的评论:

@interface

中删除 IBOutlet UIStackView *customKeyboard;

并使用:

fixedPrice.inputView = _customKeyboard;

或者:

fixedPrice.inputView = self.customKeyboard;