Iphone iOS 5中的UIKeyboardTypeNumberPad返回或完成按钮

Iphone iOS 5中的UIKeyboardTypeNumberPad返回或完成按钮,iphone,ios5,Iphone,Ios5,在iOS 3中,这一解决方法涉及创建一个customer UIButton并将其作为子视图添加到Apple键盘。当iOS 4发布时,添加子视图的视图发生了更改。因此,为了在iOS3和ios4中实现这一点,我有以下几点 -(void) addDoneButtonToNumericKeyboard { if(doneButtonIsAdded) { return; } if(doneButtonForNumericKeyboard == nil) { doneButtonForNum

在iOS 3中,这一解决方法涉及创建一个customer UIButton并将其作为子视图添加到Apple键盘。当iOS 4发布时,添加子视图的视图发生了更改。因此,为了在iOS3和ios4中实现这一点,我有以下几点

-(void) addDoneButtonToNumericKeyboard {
if(doneButtonIsAdded) {
    return;
}
if(doneButtonForNumericKeyboard == nil) {
    doneButtonForNumericKeyboard= [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    doneButtonForNumericKeyboard.frame = CGRectMake(0, 163, 106, 53);
    doneButtonForNumericKeyboard.adjustsImageWhenHighlighted = NO;
    if ([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3"]) {
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
    } else {        
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
        [doneButtonForNumericKeyboard setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    }
    [doneButtonForNumericKeyboard addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
}
// locate keyboard view
NSArray *winArray = [[UIApplication sharedApplication] windows];
if(winArray == nil || [winArray count] < 2) {
    NSLog(@"No winArray found!");
    return;
}
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
    keyboard = [tempWindow.subviews objectAtIndex:i];
    // keyboard view found; add the custom button to it
    NSLog(@"Keyboard description : %@", [keyboard description]);
    if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES || [[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) {
        NSLog(@"Attaching done button");
        [keyboard addSubview:doneButtonForNumericKeyboard];
        doneButtonIsAdded = YES;
    }
}
}
-(无效)添加按钮到数字键盘{
如果(未按按钮添加){
返回;
}
如果(数字键盘的doneButtonForNumericKeyboard==nil){
doneButtonForNumericKeyboard=[[UIButtonButtonWithType:UIButtonTypeCustom]retain];
doneButtonForNumericKeyboard.frame=CGRectMake(0,163,106,53);
数字键盘的Donebutton.adjustsImageWhenHighlighted=否;
如果([[[UIDevice currentDevice]systemVersion]hasPrefix:@“3”]){
[doneButtonForNumericKeyboard setImage:[UIImage ImageName:@“DoneUp3.png”]用于状态:UIControlStateNormal];
[doneButtonForNumericKeyboard setImage:[UIImage ImageName:@“DoneDown3.png”]用于状态:UIControlStateHighlighted];
}否则{
[doneButtonForNumericKeyboard setImage:[UIImage ImageName:@“DoneUp.png”]用于状态:UIControlStateNormal];
[doneButtonForNumericKeyboard setImage:[UIImage ImageName:@“DoneDown.png”]用于状态:UIControlStateHighlighted];
}
[doneButton for NumericKeyboard addTarget:self action:@selector(doneButton:)for ControlEvents:UIControlEventTouchUpInside];
}
//定位键盘视图
NSArray*winArray=[[UIApplication sharedApplication]windows];
if(winArray==nil | |[winArray count]<2){
NSLog(@“未找到winArray!”);
返回;
}
UIWindow*tempWindow=[[UIApplication sharedApplication]windows]对象索引:1];
UIView*键盘;

对于(int i=0;i我也注意到了这一点,到目前为止,我唯一能想到的修复方法是将它从:
keyboardWillShow:
更改为
keyboardDidShow:
。显然,“will”和“did”之间的区别是另一个讨论,但似乎是为了我的需要而修复的

我希望这有帮助

我发现的更多背景信息是,第一个对象出现在
[[UIApplication sharedApplication]windows]
中,但索引1处的第二个对象不见了。我想知道这是什么原因造成的

谢谢