2010-08-31 40 views
0

您好我有iPhone 4.0 OS的一个大问题与此代码UIKeyboard与iPhone OS 4

if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) { 
} 

状况UIKeyboard它不能正常工作。我尝试“UILayoutContainerView” 但它不工作。

请。

+1

你将不得不提供更多的信息。你期望的结果是什么,你实际上看到了什么结果。解释为什么它不起作用,以及应该如何工作。 – Jasarien 2010-08-31 14:11:32

+1

你真的不应该像这样以编程方式使用'description'方法。它用于在控制台和调试时向您显示一个漂亮的人类可读字符串。 Apple可以随时更改“description”的输出。也许你正在寻找'isKindOfClass:'? if([keyboard isKindOfClass:[UIKeyboard class]]){...} – 2010-08-31 14:48:07

回答

0

你可以试试这个代码:

- (BOOL) findKeyboard:(UIView *) superView; 
{ 
    UIView *currentView; 
    if ([superView.subviews count] > 0) { 
     for(int i = 0; i < [superView.subviews count]; i++) 
     { 

      currentView = [superView.subviews objectAtIndex:i]; 
      NSLog(@"%@",[currentView description]); 
      if([[currentView description] hasPrefix:@"<UIKeyboard"] == YES) 
      { 

       NSLog(@"Find it"); 

       return YES; 
      } 
      if ([self findKeyboard:currentView]) return YES; 
     } 
    } 

    return NO; 

} 

-(void) checkKeyBoard { 
    UIWindow* tempWindow; 

    for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; C++) 
    { 
     tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c]; 
     if ([self findKeyboard:tempWindow]) 
      NSLog(@"Finally, I found it"); 
    } 
} 

- (void)keyboardWillShow:(NSNotification *)note { 
    [self performSelector:(@selector(checkKeyBoard)) withObject:nil afterDelay:0]; 
} 

而且你还需要添加该代码在AppDelegate中发挥作用didFinishLaunchingWithOptions:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
+1

我知道如何创建自定义键盘。如果有人想知道请评论这篇文章^ __ ^ – 2010-09-21 02:05:08

0
@"<UIPeripheralHostView" will work instead of @"<UIKeyboard" 

说不上为什么。

那么你能告诉我那么:如何确定UIKeyboard类中的键盘类型?