2010-08-31 71 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類中的鍵盤類型?