2011-01-10 13 views
0

私はビューに10個のテキストフィールドを持っています。私は電話と郵便番号の2つのテキストフィールドが必要です。だから私は電話とZIPのテキストフィールドをクリックすると、数字キーパッドを表示したい。iPhoneの多くのテキストフィールド用の数字パッドのカスタム完了ボタン

カスタム完了ボタンは、次のようにlinkを使用して作成しました。このコードは、テキストフィールドが1つだけの場合に便利です。複数のテキストフィールドで失敗します。いずれかの問題が解決しましたか?

答えて

0

Interface Builderでは、各テキストフィールドをクリックし、属性ペインでText Traitsを表示します。 キーボードの下で、テキストフィールドをクリックしたときに表示する必要があるキーパッドのタイプにカスタマイズできます。 (画面上の他の非数パッドのテキストフィールドがある場合に最適です。)ここで

2

はあなたのためのソリューションがある

inputAccessoryView

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 
    numberToolbar.barStyle = UIBarStyleBlackTranslucent; 
    numberToolbar.items = [NSArray arrayWithObjects: 
         [[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)], 
        nil]; 
    [numberToolbar sizeToFit]; 
    numberTextField.inputAccessoryView = numberToolbar; 
} 

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

-(void)doneWithNumberPad{ 
    NSString *numberFromTheKeyboard = numberTextField.text; 
    [numberTextField resignFirstResponder]; 
} 
関連する問題