私はプログラム的にiPhoneのキーボード上の「スイッチ数パッドに」ボタンを発射することができます

StackOverflow https://stackoverflow.com/questions/2349044

  •  23-09-2019
  •  | 
  •  

質問

私は、プログラム番号への手紙からスイッチへのiPhoneのキーボードの原因となるセレクタを起動する方法を見つけたいです。私は、キーボードの種類を切り替えることができることを承知していますが、私はキーボードの種類を切り替えることなくこれを行う方法があるかどうかを知りたい。

役に立ちましたか?

解決

あなたは、少なくともではない公的サポートされている任意の方法で、プログラム的keyplanes(シンボルkeyplaneに数値keyplaneにアルファベットkeyplane)を切り替えることはできません。あなたが述べたように、あなたはファーストレスポンダのテキスト入力形質のキーボードの種類や外観を変更することができますが、これはユーザーのみが行うことができるはず異なるkeyplanes、間の切り替えとは異なります。

他のヒント

ジャスト回避策: あなたは数字パッドにアルファベットからのUITextFieldを編集しているときのようなアクティブなキーボードのkeyplaneを変更したい場合は、まず次のresignFirstResponder、テキストフィールドに最終的becomeFirstResponderメッセージを送って、テキストフィールドのKEYBOARDTYPEプロパティに新しい値を設定します。例えばます。

textfield.keyboardType = UIKeyboardTypeNumberPad;
[textField resignFirstResponder];
[textField becomeFirstResponder];

スウィフトます:

textField.keyboardType = .numberPad
textField.resignFirstResponder()
textField.becomeFirstResponder()

希望それは;-D

のに役立ちます

これを見てください

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil)
    {
        cell = [ [ [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0f];
        cell.textLabel.textColor = [UIColor whiteColor];
    }

    UITextField * textField = [ [ UITextField alloc] initWithFrame:CGRectMake(55.0f, 10.0f, 230.0f, 31.0f)];
    textField.textColor = [UIColor whiteColor];

    textField.delegate = self;
c this care fully   ///////////if(indexPath.row == 0)
c this care fully   //  textField.keyboardType = UIKeyboardTypeDefault;
c this care fully   //else
c this care fully   //  textField.keyboardType = UIKeyboardTypePhonePad;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    [cell.contentView addSubview:textField];

    if(indexPath.row == 0)
    {
        self.sender = textField;
        cell.textLabel.text = @"From:";
    }
    else 
    {
        self.mobileNumber = textField; 
        cell.textLabel.text = @"To:";
    }
    [textField release];
    if(indexPath.row == 1)
    {
        UIButton * contactsButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
        [contactsButton addTarget:self action:@selector(addContact:) forControlEvents:UIControlEventTouchUpInside];
        cell.accessoryView = contactsButton;

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}

私は "完全にこのケアC" のコメントどこをチェック

これは、あなたがキーボードをプログラムで切り替えるのに役立ちます。

カスタムのために

を使用すると、キーボードのaccessoryView

のを使用することができ、キーボードの種類を切り替えます

コードにするために型スイッチング用キーボードaccessoryView ...(うまくいけば切り取らコードが理解しやすい)

// You can call this in viewDidLoad (initialization of the ABC/Done view) 
- (void)setAccessoryViewForKeyboard{
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 44)];
    UIBarButtonItem *changeKeyboard = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(switchKeyboardTypes)];
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *choose = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"") style:UIBarButtonItemStylePlain target:_textField action:@selector(resignFirstResponder)];
    [toolbar setItems:@[changeKeyboard, space, choose]];
    [self.textField setInputAccessoryView:toolbar];

}

// changing the left button text ('ABC' and '123')
- (void)setTitleForSwitchingKeyboardButton{
    NSString *firstButtonText = self.textField.keyboardType == UIKeyboardTypeDefault ? NSLocalizedString(@"123", @"") : NSLocalizedString(@"ABC", @"");
    [[[(UIToolbar *)self.textField.inputAccessoryView items] firstObject] setTitle:firstButtonText];
}


- (void)switchKeyboardTypes{
    if (self.textField.keyboardType == UIKeyboardTypeDefault){
        [self setTextFieldKeyboardType:UIKeyboardTypeNumberPad];
    } else {
        [self setTextFieldKeyboardType:UIKeyboardTypeDefault];
    }
}

- (void)setTextFieldKeyboardType:UIKeyboardTypeNumberPad:(UIKeyboardType)keyboardType {

    [self.textField setKeyboardType:keyboardType];

    if ([_textField isFirstResponder]) {

        _changingKeyboardType = YES;
        [self.textField resignFirstResponder];
        [self.textField becomeFirstResponder];
        _changingKeyboardType = NO;
    }

    [self setTitleForSwitchingKeyboardButton];
}


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (!_changingKeyboardType) {
        // you can set the default keyboard type here:
        // [self setTextFieldKeyboardType:UIKeyboardTypeNumberPad];
        // [self setTextFieldKeyboardType:UIKeyboardTypeDefault];
        [self setTitleForSwitchingKeyboardButton];
    }
 }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top