我怎么能在iPhone消失数字键盘因为它没有返回键,这意味着它不会向Disapperiang IPhone数字键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
我怎么能在iPhone消失数字键盘因为它没有返回键,这意味着它不会向Disapperiang IPhone数字键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
回应试试这个:
[theTextField resignFirstResponder];
那么你在我上面写过的函数中这样做,就像这样。 无论如何,我应该把这个代码工作? – itsaboutcode 2009-09-10 22:53:33
我在我的视图中有很多文本框,它也不适用于数字键盘 – 2012-06-19 13:24:57
下面是答案..
-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event
{
//[URL resignFirstResponder];
//[Password resignFirstResponder];
[speedField resignFirstResponder];
[super touchesBegan:touches withEvent:event ];
}
当我在一个视图中有子视图时不工作 – 2012-06-19 13:22:35
在这里,你去。用这个扩展你的UIViewController类。但是我们怎么知道它是完成按钮? Adding Done Button to Only Number Pad Keyboard on 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];
}
-1这是一个完全的黑客,不应该使用。如果苹果决定将“UIKeyboard”的名称更改为“UIKBView”,该怎么办?您绝不应该依赖未记录的行为或实现细节来使代码正常工作。如果你需要没有无证材料的行为,请提交一个错误。 – 2010-12-05 21:30:02
为什么不使用“Numbers and Punctuation”键而不是“Numeric”?这将节省您的时间
使用resignFirstResponder中的touchesBegan,像这样:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
if(touch.phase == UITouchPhaseBegan) {
[self.myTextField resignFirstResponder];
}
}
您可能需要,如果你不知道在哪里焦点当前位于调用此对多个文本字段;我没有测试过这种情况。
此外,在界面生成器,你将需要启用该视图的“已启用用户交互”复选框,或编程使用:
myView.userInteractionEnabled = YES;
重复的: - - - - - - - - 这只是在搜索结果的第一页... –
2009-09-10 22:54:06
恐怕你错了,因为他们都在谈论当键盘不是数字类型,我知道如何禁用键盘,当它不是数字,不同的情况下,当你不得不消失“数字键盘”。在提出这个问题之前我搜索一下。 – itsaboutcode 2009-09-10 22:58:35
一旦用户输入号码,您可以轻松地在屏幕上放置一个按钮以关闭键盘。这不是电话应用程序的工作原理吗?或者你可以在键盘上方放一个工具栏,上面有一个“don”按钮,或者任意数量的东西(在x秒不活动后自动关闭键盘,一旦字段中的文本确认等等) – 2009-09-10 23:11:57