2014-07-15 3 views
0

일부 UITextViews가있는보기가 있습니다. 사용자는 개인 데이터, 이름, 성, 이메일 등을 입력 할 수 있습니다 편집은 사용자가 오른쪽 상단에 "완료"안타 뷰 가 다시이 같은 이전보기 탐색 완료되면 :UIAlertView는 popViewControllerAnimated를 호출하지 않아야합니다.

- (void)save:(id)sender 
{ 

    [self.view.window endEditing:YES]; 

    if (self.data ...) 
    { 
     [self updateUser]; 
     [self.navigationController popViewControllerAnimated:YES]; 
    } 

} 

고객이 이메일과 같은 일부 인증을 추가하도록 요청했습니다. 유효성 검사 후에 UIAlertView는 데이터 입력이 유효하지 않았 음을 알리고 따라서 데이터는 저장되지 않습니다. 내 문제는 AlertView의 OK 단추가 "save"메서드를 호출하고 navigationController가 호출되고 popViewControllertAnimated가 호출된다는 것입니다.

여기에서 문제는 UIAlertView 이후에 popViewControllerAnimated를 통해 이전보기로 자동 탐색하는 것을 피하고 더 정확하게 수정보기 및 유형 유효 기간을 유지하고 싶습니다.

경고 뷰 코드는 -(BOOL)textFieldShouldEndEditing:(UITextField *)textField 방법을 통해 호출

- (void)alertInvalid { 

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""                  message:NSLocalizedString(@"res_CurrentPasswordErrorAlert",nil) 
           delegate:nil cancelButtonTitle: NSLocalizedString(@"res_OK",nil) otherButtonTitles:nil]; 

    [alertView show]; 

} 

이다. 그래서, 현재의 UITextView가 다시 응답하도록 경고 메시지를 보낸 후 어떻게 코드를 수정합니까?

+1

입니다. 둘 중 하나에서 저장 메소드를 호출해야합니다. – Popeye

+1

'UIAlertView Delegate' 메소드를 사용하십시오. –

+1

dismissWithClickedButtonIndex 또는 on : clickedButtonAtIndex (UIAlertView) delete 메소드에서보기를 탐색해야합니다. – iBhavin

답변

1

UIAlertViewDelegate를 사용하고자 할 것입니다. 여기

은 기준입니다 :

https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html

그러나 결론은이 방법을 구현하는 것입니다 :

  • (무효) alertView : (UIAlertView *) alertView clickedButtonAtIndex을 : (NSInteger) buttonIndex

그래서 구현할 때 단추 인덱스를 확인하십시오. 색인에 따라 논리에서 다음에 발생할 일을 제어 할 수 있습니다. 당신이 당신의 UIAlertView를 인스턴스화 할 때

,이 같은 대리자를 설정해야합니다 : 당신의 alertView 위임 방법의 설정이 무엇

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""               
                message:NSLocalizedString(@"res_CurrentPasswordErrorAlert",nil) 
                delegate:self // this is the key! 
              cancelButtonTitle:NSLocalizedString(@"res_OK",nil) 
              otherButtonTitles:nil]; 
+0

clickedButtonAtIndex에서 필요한 코드는 무엇입니까? 난 그냥 UITextView 첫 번째 응답자와 동일한보기에 머물고 싶습니다. – cateof

+0

clickedButtonAtIndex에서 필요한 코드는 원하는 작업에 따라 달라집니다. buttonIndex 매개 변수를 전환 한 다음 그에 따라 논리를 코딩 할 수 있습니다. – joelg