2014-09-24 38 views
-3

UITextField在iOS8中不起作用,點擊文本框時沒有看到鍵盤,也沒有看到任何崩潰。但它在iOS7設備上工作正常。 我使用的是以下代碼:UITextField無法在IOS8中工作

UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"TF_MSG_ ENTER", @"") message:@"\n\n" delegate:self cancelButtonTitle:NSLocalizedString(@"TF_CANCEL_TEXT", @"") otherButtonTitles:NSLocalizedString(@"TF_MSG_ OK", @""), nil]; 

    UITextField *txBookmarkName = nil; 

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) 
    { 
    txBookmarkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0f, 45.0f, 260.0f, 25.0f)]; 
    myAlert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    txBookmarkName = [myAlert textFieldAtIndex:0]; 
    } 
    else 
    { 
    txBookmarkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0f, 45.0f, 260.0f, 25.0f)]; 
    IF_PRE_IOS4 (
       [txBookmarkName release], txBookmarkName = nil; 
       txBookmarkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0f, 65.0f, 260.0f, 25.0f)]; 
       ); 
    } 
    [txBookmarkName setDelegate:self]; 
    [txBookmarkName setText:nameLabel.text]; 
    myAlert.tag=TF_TAG_TEXT_FIELD_RENAME; 
    [txBookmarkName setBorderStyle:UITextBorderStyleRoundedRect]; 
    [txBookmarkName becomeFirstResponder]; 
    [txBookmarkName setAutocorrectionType:UITextAutocorrectionTypeNo]; 
    txBookmarkName.tag=TF_TAG_TEXTFIELD; 
    [myAlert addSubview: txBookmarkName]; 
    [myAlert setFrame:CGRectMake(0, 0, 300,50)]; 
    IF_PRE_IOS4 (
          CGAffineTransform t = CGAffineTransformMakeTranslation(0.0f, 85.0f); 
          [myAlert setTransform: t]; 
          ); 
    [myAlert show]; 
    [txBookmarkName release]; 
    if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0) 
    [myAlert release]; 

請幫幫我。

在此先感謝。

+0

你使用模擬器來測試它嗎? – 2014-09-24 10:17:45

+0

它不工作在模擬器以及設備也... – 2014-09-24 10:23:32

+0

是UITextField的userInteractionEnabled和啓用屬性設置爲YES? – 2014-09-24 10:26:59

回答

2

選中此項:

打開模擬器。

轉到硬件。

然後選擇鍵盤。

然後選擇iOS用戶相同的佈局OS X

模擬器 - >硬件 - >鍵盤 - > iOS用戶相同的佈局OS X

enter image description here

它的工作:)

相關問題