2010-02-08 3 views
0

지난 한 주 동안이 문제를 꼼짝 않고 들여다 보았습니다. 무수한 조의 컵, 고양이가 키보드를 밟는 것, 나중에 랩톱에서 내려 주길 원하는 여자 친구 - 나는 아직도 이것을 이해할 수 없다. 희망 나는 무언가를 매우 바보 (100 % 기회)를하고있다.내가 누락 된 부분은이 숫자를 내 번호 패드에 추가하는 것입니까?

숫자 패드에 소수점을 추가하는 코드가 있습니다. 대부분의 코드는 여기 (http://brygruver.squarespace.com/blog/2009/10/1/creating-a-custom-number-pad.html?lastPage=true&postSubmitted=true)에서 가져 왔고 그의 코드를 사용하고 있지만 십진수와 십진수의 이미지를 내 총 5 개 필드의 마지막 두 필드에만 추가하기 위해 약간 수정했습니다.

여기
- (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)에 표시됩니다. 그래서 소수점을 보여주는 코드가 아니라 내가 가진 유효성 검증을 보여 주어야합니다.

여기에 제가 가진 유효성 확인이 있습니다. 나는 텍스트 필드가 nil이거나 첫 번째 응답자 인 채로 공을 떨어 뜨리고 있다고 생각하고 있습니까?

- (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:으로 전화해야합니다.

관련 문제