切换到另一个视图时,UITextField不显示键盘

时间:2012-01-07 16:04:10

标签: ios keyboard uitextfield uitextfielddelegate

从开始屏幕切换到另一个控制器(它有一个UITextField)。当用户点按UITextField时,如何才能显示键盘?在演示项目中一切正常,但它不适用于我的主项目。这是我用来切换视图的代码:

-(void) switchView:(UIViewController *)currentCtrl toView:(UIViewController *)nextCtrl
{
@try { 
    UIWindow *theWindow = [[UIApplication sharedApplication]keyWindow]; 
    theWindow.rootViewController = nextCtrl;
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.75f];
    [animation setType:kCATransitionPush];
    if (isBack) {
        [animation setSubtype:kCATransitionFromLeft];
    }
    else [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [[theWindow layer] addAnimation:animation forKey:@"SwitchToView"];
    nextCtrl.view.frame = [[UIScreen mainScreen]applicationFrame];
    // back
    if (isBack == NO) {
        [stackController addObject:currentCtrl];    
    }
    self.currentController = nextCtrl;
    isBack = NO;
}
@catch (NSException *exception) {}

}
-(void) goToPreviousView
{
if (nil != self.currentController && stackController!=nil && [stackController count]>0) 
{
    UIViewController *previousView = [[stackController lastObject]retain];
    [stackController removeLastObject];
    if (previousView) {
        isBack = YES;
        [self switchView:self.currentController toView:previousView];
    }
}

}

如果我使用[self presentModalViewController:colorPickerView animated:YES];,那么在初始颜色选择器视图时,我会尝试:

txtHex.keyboardType = UIKeyboardTypeASCIICapable;
txtHex.returnKeyType = UIReturnKeyDone;
txtHex.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
txtHex.delegate = self;
txtHex.enabled = YES;
[txtHex becomeFirstResponder];

它有效但不完美。问题似乎是文本字段无法触发委托方法。

-(void) textFieldDidBeginEditing:(UITextField *)textField
{
txtCurrent = textField;
}

0 个答案:

没有答案