0

リターンキーがないため、iPhoneの数字キーボードを非表示にする方法は、応答しないことを意味します

- (BOOL)textFieldShouldReturn:(UITextField *)textField
4

5 に答える 5

3

次のように、touchesBeganで rejectFirstResponderを使用します。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch * touch = [touches anyObject];
    if(touch.phase == UITouchPhaseBegan) {
        [self.myTextField resignFirstResponder];
    }
}

フォーカスが現在どこにあるかわからない場合は、複数のテキスト フィールドでこれを呼び出す必要がある場合があります。私はそのケースをテストしていません。

さらに、Interface Builder では、ビューの [User Interaction Enabled] チェックボックスを有効にするか、プログラムで次を使用する必要があります。

myView.userInteractionEnabled = YES;
于 2013-01-21T10:33:53.257 に答える
2

これが答えです..

-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event

{

    //[URL resignFirstResponder];

    //[Password resignFirstResponder];

    [speedField resignFirstResponder];

    [super touchesBegan:touches withEvent:event ];

}
于 2010-11-10T08:35:18.680 に答える
0

これを試して:

[theTextField resignFirstResponder];
于 2009-09-10T22:49:12.930 に答える
0

「数値」の代わりに「数字と句読点」キーボードを使用しないのはなぜですか? それはあなたの時間を節約します

于 2011-10-15T16:37:20.707 に答える
-2

どうぞ。これで UIViewController クラスを拡張します。しかし、それが完了ボタンであることをどうやって知るのでしょうか? iPhoneの数字パッドキーボードのみに完了ボタンを追加する

//
//  UIViewController+NumPadReturn.m
//  iGenerateRandomNumbers
//
//  Created by  on 12/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "UIViewController+NumPadReturn.h"


@implementation UIViewController (NumPadReturn)

-(void) viewDidLoad{
    // add observer for the respective notifications (depending on the os version)
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(keyboardDidShow:) 
                                                     name:UIKeyboardDidShowNotification 
                                                   object:nil];     
    } else {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(keyboardWillShow:) 
                                                     name:UIKeyboardWillShowNotification 
                                                   object:nil];
    }

}


- (void)keyboardWillShow:(NSNotification *)note {
    // if clause is just an additional precaution, you could also dismiss it
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2) {
        [self addButtonToKeyboard];
    }
}

- (void)keyboardDidShow:(NSNotification *)note {
    // if clause is just an additional precaution, you could also dismiss it
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        [self addButtonToKeyboard];
    }
}

- (void)addButtonToKeyboard {
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
        [doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
        [doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
    } else {        
        [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
        [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    }
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];

        // keyboard found, add the button
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
            if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
                [keyboard addSubview:doneButton];
        } else {
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                [keyboard addSubview:doneButton];
        }
    }


}

- (void)doneButton:(id)sender {
    NSLog(@"doneButton");
    [self.view endEditing:TRUE];
}
于 2010-12-05T17:33:10.573 に答える