2013-10-21 2 views
2

현재 iOS6 및 iOS7을 지원해야하는 앱에서 작업하고 있습니다.UIAlertView alertViewShouldEnableFirstOtherButton : iOS7에서 잘못된 버튼을 사용 중지합니다.

내가 이런 경고를 만드는거야 : 나는 다음과 같은 프로토콜 방식을 구현하고있어 대리자에서

self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil) 
                message:NSLocalizedString(@"MessageTextNewCategory", nil) 
                delegate:self 
              cancelButtonTitle:nil 
              otherButtonTitles:NSLocalizedString(@"ButtonOK", nil), NSLocalizedString(@"ButtonCancel", nil), nil] autorelease]; 

self.newCategoryAlertView.cancelButtonIndex = 1; 
self.newCategoryAlertView.tag = alertViewTypeNewCategory; 
self.newCategoryAlertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
[self.newCategoryAlertView textFieldAtIndex:0].delegate = self; 
[self.newCategoryAlertView textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences; 
[[self.newCategoryAlertView textFieldAtIndex:0] setReturnKeyType:UIReturnKeyDone]; 
[[self.newCategoryAlertView textFieldAtIndex:0] setKeyboardAppearance:UIKeyboardAppearanceDefault]; 
[self.newCategoryAlertView textFieldAtIndex:0].enablesReturnKeyAutomatically = YES; 

[self.newCategoryAlertView show]; 

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView 
{ 
    if(alertView.tag == alertViewTypeNewCategory) 
    { 
     UITextField *textField = [alertView textFieldAtIndex:0]; 
     if (!textField.text || [textField.text isEqualToString:@""]) 
     { 
      return NO; 
     } else { 
      return YES; 
     } 
    } else { 
     return YES; 
    } 
} 

내 문제는 왼쪽 버튼이 iOS6의 비활성화 실행이 있다는 것이다 (예상대로), iOS7에서 실행하면 오른쪽 버튼이 비활성화됩니다.

델리게이트 메서드 내에서 cancelButtonIndex 및 firstOtherButtonIndex 값을 확인했으며 iOS7 및 iOS6에서 동일합니다.

내가 뭘 잘못하고 있는지 힌트가 있으십니까? 또는이 문제를 해결할 수있는 해결 방법은 무엇입니까?

답변

4

iOS 7이 색인 당 버튼 정렬 순서를 변경 한 것처럼 보입니다. 나는 귀하의 코드를 시도하고 정렬 순서를 확인하기 위해 몇 가지 단추를 추가했습니다. UIAlertView 들어

[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil) 
                 message:NSLocalizedString(@"MessageTextNewCategory", nil) 
                 delegate:self 
               cancelButtonTitle:nil 
               otherButtonTitles:NSLocalizedString(@"ButtonOK", nil), NSLocalizedString(@"ButtonCancel", nil),NSLocalizedString(@"Third Button", nil),NSLocalizedString(@"Fourth Button", nil),NSLocalizedString(@"Fifth Button", nil), nil]; 

가기하지만 번째 버튼에있다

enter image description here

먼저 버튼 "ButtonOK"

아이폰 OS (7)에서 마지막 위치에있는 이전의 iOS 버전과 동일한 오름차순으로 배치 된 버튼을 나머지.

그래서, 당신은 [[UIDevice currentDevice] systemVersion]를 사용하여 iOS 버전을 확인하고 내가 지금하고 있어요 어떻게 그게 전부 때문에 가능으로

if (iOS 7) { 
    self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil) 
               message:NSLocalizedString(@"MessageTextNewCategory", nil) 
               delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:NSLocalizedString(@"ButtonCancel", nil),NSLocalizedString(@"ButtonOK", nil), , nil] autorelease]; 
    }else{ 
     self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"MessageTitleNewCategory", nil) 
               message:NSLocalizedString(@"MessageTextNewCategory", nil) 
               delegate:self 
             cancelButtonTitle:nil 
             otherButtonTitles:NSLocalizedString(@"ButtonOK", nil), NSLocalizedString(@"ButtonCancel", nil), nil] autorelease]; 
    } 
+0

내가 답을 표시 할 수 있습니다 할 수 있습니다. 그러나 실제로 문제에 대한 설명이나 해결책이 아닙니다. UIAlertView가 firstOtherButtonIndex를 무시하고 항상 첫 번째 버튼을 비활성화하는 것처럼 보입니다. –

+0

수락을 보내 주셔서 감사합니다. 네, 맞습니다. UIAlertView는 iOS 6과 iOS 7 모두에서 첫 번째 버튼을 비활성화하는 것입니다. – nikhilgohil11

+1

우리가이 방법으로 해결해야하는 농담은 거의 ... 지금도 2 년 후 : –

관련 문제