2010-02-08 15 views
0

我一直在盯着過去一週的這個問題。無數杯喬,踩着我的鍵盤的貓,還有女朋友想讓我晚點離開筆記本電腦 - 我仍然無法弄清楚這一點。希望我正在做一些非常愚蠢的事情(100%機率),我總是在尋找。我在將數字加到我的數字鍵盤上時缺少什麼?

我有一些代碼附加到數字鍵盤的小數。大部分代碼是從這裏取得的(http://brygruver.squarespace.com/blog/2009/10/1/creating-a-custom-number-pad.html?lastPage=true&postSubmitted=true),我使用他的代碼,但修改了一下,只將小數點和圖像附加到我總共五個字段的最後兩個字段。

這裏是我的代碼,與表示十進制圖像,並將其追加到輸入:

- (void)textFieldDidBeginEditing:(UITextField *)textField { 
    // We need to access the dot Button declared in the Delegate. 
    helloAppDelegate *appDelegate = (helloAppDelegate *)[[UIApplication sharedApplication] delegate]; 

    // Only if we are editing within the Number Pad Text Field do we want the dot. 
    if (textField == txtUserName4) { 
     // Show the Dot. 
     appDelegate.dot.hidden = NO; 
    } 
    else if (textField == txtUserName5) { 
     // Show the Dot. 
     appDelegate.dot.hidden = NO; 
    } 
    else { 
     // Otherwise, Hide the Dot. 
     appDelegate.dot.hidden = YES; 
    } 
} 

- (void)addDecimal:(NSNotification *)notification { 
    // Apend the Decimal to the TextField. 
    if (txtUserName4.editing) { 
     txtUserName4.text = [txtUserName4.text stringByAppendingString:@"."]; 
    } 
    else if (txtUserName5.editing) { 
     txtUserName5.text = [txtUserName5.text stringByAppendingString:@"."]; 
    } 

這裏是發生了什麼(http://screencast.com/t/OTNhODRiYjAt)的視頻。小數點不顯示,除非我出現警報錯誤,然後它顯示正確的兩個字段。因此,我關閉了字段驗證和 - 令人震驚的 - 最後兩個字段(http://screencast.com/t/ZmQyOTc1MT)上的小數顯示。所以它不能是顯示小數的代碼,而是我有的驗證。

這裏是我的驗證。我在想我的文本域是零還是第一響應者?

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    if (textField == txtUserName) 
    { 
     NSString *userNameOne = txtUserName.text; 
     double numOne = [userNameOne doubleValue]; 

     if(numOne < 30 || numOne > 80) 
     { 

      //show alert 
      //release alert 

      //if there is alert then clear out the field and make that the FR 


      [txtUserName becomeFirstResponder]; 
      txtUserName.text = nil; 
     } 
     else 
     { 
      [txtUserName2 becomeFirstResponder]; 
     } 
    } 

    else if (textField == txtUserName2) 
    { 

     NSString *userNameThree = txtUserName2.text; 
     float numTwo = [userNameThree doubleValue]; 

     if (numTwo < 20 || numTwo > 32) 
     { 
      //show alert 
      //release alert 

      //if there is alert then clear out the field and make that the FR 


      [txtUserName2 becomeFirstResponder]; 
      txtUserName2.text = nil; 
     } 
     else 
     { 
      [txtUserName3 becomeFirstResponder]; 
     } 
    } 
    else if (textField == txtUserName3) 
    { 
     NSString *userNameThree = txtUserName3.text; 
     float numThree = [userNameThree doubleValue]; 

     if (numThree < 475 || numThree > 650) 
     { 
      //show alert 
      //release alert 

      //if there is alert then clear out the field and make that the FR 


      [txtUserName3 becomeFirstResponder]; 
      txtUserName3.text = nil; 
     } 
     else 
     { 
      [txtUserName4 becomeFirstResponder]; 

     } 
    } 
    else if (textField == txtUserName4) 
    { 
     NSString *userNameFour = txtUserName4.text; 
     double numFour = [userNameFour doubleValue]; 

     if (numFour < 0.5 || numFour > 3.00) 
     { 

      //show alert 
      //release alert 

      //if there is alert then clear out the field and make that the FR 


      [txtUserName4 becomeFirstResponder]; 
      txtUserName4.text = nil; 
     } 
     else 
     { 
      [txtUserName5 becomeFirstResponder]; 
     } 
    } 
    else if (textField == txtUserName5) 
    { 
     NSString *userNameFive = txtUserName5.text; 
     double numFive = [userNameFive doubleValue]; 

     if (numFive > 0.80) 
     { 
      //show alert 
      //release alert 

      //if there is alert then clear out the field and make that the FR 
      [txtUserName5 becomeFirstResponder]; 
      txtUserName5.text = nil; 
     } 
     else 
     { 
      [txtUserName5 resignFirstResponder]; 
     } 
    } 
} 

我真的很爲難,但至少想通了,這件事情與我的驗證的東西混合起來......

編輯: 我發現,如果我註釋掉else,使下一個場第一響應者,那麼所有事情都應該如此。

這樣說,刪除else真的會傷害我的任何驗證?整個驗證是在我使用基本鍵盤時使用'done'和'next'按鈕的想法。現在,我看到我的整個驗證代碼缺乏:)

回答

0

最有可能當您撥打-becomeFirstResponder時,鍵盤正在重繪,這可能是推動鍵盤視圖上方的魔法「點」視圖應該是浮在上面。每次切換第一響應者時,您可能需要用「點」視圖呼叫-bringSubviewToFront:

相關問題