2016-11-23 5 views
0

UIAlertControllerStyleActionSheet의 에 대한 목표 -c 쓰기를 사용하고 있습니다.iOS 팝업 표시가 두 번 표시됩니다.

iPhone에서 알림 시트를 표시하고 iPad에서 popoverPresentationController을 표시하고 싶습니다.

먼저 UIPopoverPresentationControllerDelegate 대리인을 설정했습니다.

버튼을 클릭하면 팝업이 올바르게 표시됩니다.

하지만 화면을 클릭하여 팝업을 닫습니다. 아래에 경고가 표시됩니다.

[경고] < _UIPopoverBackgroundVisualEffectView 0x14be52ef0>에 불투명도를 적용하라는 메시지가 표시됩니다. 이렇게하면 불투명도가 1로 돌아갈 때까지 효과가 깨집니다.

이제 버튼을 클릭하면 다시 팝보기가 표시됩니다.

로그가 아래에 표시됩니다.

인해 캐치되지 않는 예외 'NSGenericException'응용 프로그램 종료, 이유는 : '응용 프로그램이 스타일 UIAlertControllerStyleActionSheet의 UIAlertController()을 선물했다. 이 스타일을 사용하는 UIAlertController의 modalPresentationStyle은 UIModalPresentationPopover입니다. 경고 컨트롤러의 popoverPresentationController를 통해이 팝업에 대한 위치 정보를 제공해야합니다. sourceView와 sourceRect 또는 barButtonItem을 제공해야합니다. 경고 컨트롤러를 제시 할 때이 정보를 알 수없는 경우 UIPopoverPresentationControllerDelegate 메소드 -prepareForPopoverPresentation에 정보를 제공 할 수 있습니다. *** 먼저 투사 호출 스택 : (0x18d9a41c0 0x18c3dc55c 0x19418a8b0 0x193ac60a8 0x193ac3df4 0x193a08d0c 0x1939faac0 0x19376a22c 0x18d9517dc 0x18d94f40c 0x18d94f89c 0x18d87e048 0x18f2ff198 0x1937e2b50 0x1937dd888 0x10011198c의 0x18c8605b8) 의 libC++ abi.dylib : NSException

형 캐치되지 제외 종료

누구든지 문제를 해결하는 방법을 알고 있습니까?

내 코드는 다음과 같습니다 :

@interface ViewController()  <...UITextViewDelegate,UITextFieldDelegate...> { 
     UIAlertController *alertTypeAlertController; 
     UIAlertAction *alertType1Action; 
     UIAlertAction *alertType2Action; 
     UIPopoverPresentationController *popPresenter; 
    } 

- (void)viewDidLoad { 
     [super viewDidLoad]; 


    alertTypeAlertController = [UIAlertController 
          alertControllerWithTitle:@"selecte one:" 
          message:nil 
          preferredStyle:UIAlertControllerStyleActionSheet]; 

alertType1Action = [UIAlertAction 
        actionWithTitle:@"Type1" 
        style:UIAlertActionStyleDefault 
        handler:nil]; 
alertType2Action = [UIAlertAction 
        actionWithTitle:@"Type2" 
        style:UIAlertActionStyleDefault 
        handler:nil]; 
    [alertTypeAlertController addAction: alertType1Action]; 
    [alertTypeAlertController addAction: alertType2Action]; 

    // for ipad 
    popPresenter = [alertTypeAlertController             popoverPresentationController]; 

    popPresenter.permittedArrowDirections = UIPopoverArrowDirectionLeft; 

    popPresenter.delegate = self; 
    popPresenter.sourceView = self.theTypeBtn;      
    popPresenter.sourceRect = CGRectMake(230, 22, 10, 10); 

    .... 
    } 

    - (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { 
// called when a Popover is dismissed 
    } 

    - (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { 

// return YES if the Popover should be dismissed 
// return NO if the Popover should not be dismissed 
return YES; 
    } 

    -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { 

return UIModalPresentationNone; 
    } 
enter code here 

가 대단히 감사합니다.

답변

2

을 해제 한 ViewController 개체에서 강력하게 참조하는 개체 인 UIAlertControllerUIPopoverPresentationController은 해제 할 수 없습니다.


내가 나중에 문제가 당신이 대신 새로 만들어야합니다, 당신이 이동할 수있는 viewDidLoad 방법으로 한 번 popPresenter 을 만들고 당신이 버튼을 터치 할 때마다 제시하려고한다는 것입니다 발견 viewDidLoad에의 새로운 방법에 대한 코드 및 터치 이벤트에 의해 호출은 다음과 같이 수정 : 난 그냥 당신의 코드를 수정하고

- (void)makePopover 
{ 
    alertTypeAlertController = [UIAlertController 
           alertControllerWithTitle:@"selecte one:" 
           message:nil 
           preferredStyle:UIAlertControllerStyleActionSheet]; 

    alertType1Action = [UIAlertAction 
         actionWithTitle:@"Type1" 
         style:UIAlertActionStyleDefault 
         handler:nil]; 
    alertType2Action = [UIAlertAction 
         actionWithTitle:@"Type2" 
         style:UIAlertActionStyleDefault 
         handler:nil]; 
    [alertTypeAlertController addAction: alertType1Action]; 
    [alertTypeAlertController addAction: alertType2Action]; 

    // for ipad 
    popPresenter = [alertTypeAlertController             popoverPresentationController]; 

    popPresenter.permittedArrowDirections = UIPopoverArrowDirectionLeft; 
    popPresenter.canOverlapSourceViewRect = YES; // adding this line 
    popPresenter.delegate = self; 
    popPresenter.sourceView = self.theTypeBtn; 
    popPresenter.sourceRect = CGRectMake(230, 22, 10, 10); 
} 
- (IBAction)touchButton:(id)sender { 
    [self makePopover]; 
    [self presentViewController:alertTypeAlertController animated:YES completion:nil]; 
} 
+0

나는, 결과는 여전히 같은 오류를 표시한다 "UIPopoverPresentationController * popPresenter"전에 __weak를 추가하려고합니다. :( – dickfala

+0

검사 두 번째 팝업 당신이 (2)를 제시하려고하면 self.presentedViewController는 무기 호, 일반적으로 응용 프로그램이 충돌하는 경우 보기 컨트롤러. –

+0

첫 번째 클릭 버튼을 확인하고, pop은 nil (self.presentedViewController)이지만 올바르게 표시됩니다. 충돌은 발생하지 않지만 두 번째 버튼을 클릭해도 팝업은 계속 사라집니다. @@ – dickfala

0

가 작업하거나하지 않는 경우, 확인하시기 바랍니다.

- (IBAction)actionButton:(UIButton*)sender { 
     alertTypeAlertController = [UIAlertController 
          alertControllerWithTitle:@"selecte one:" 
          message:nil 
          preferredStyle:UIAlertControllerStyleActionSheet]; 

     alertType1Action = [UIAlertAction 
        actionWithTitle:@"Type1" 
        style:UIAlertActionStyleDefault 
        handler:nil]; 
     alertType2Action = [UIAlertAction 
        actionWithTitle:@"Type2" 
        style:UIAlertActionStyleDefault 
        handler:nil]; 
     [alertTypeAlertController addAction: alertType1Action]; 
     [alertTypeAlertController addAction: alertType2Action]; 

    // for ipad 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
     popPresenter = [alertTypeAlertController             popoverPresentationController];  
     popPresenter.permittedArrowDirections = UIPopoverArrowDirectionLeft; 

     popPresenter.delegate = self; 
     popPresenter.sourceView = self.theTypeBtn;      
     popPresenter.sourceRect = CGRectMake(230, 22, 10, 10); 
    } 
    [self presentViewController:alertTypeAlertController animated:YES completion:nil]; 
    } 
+0

나는 방법을 시도, 내가 버튼을 핥는다면, 그것은 추락 할 것이다. 로그 : *** 캐치되지 않은 예외 'NSInvalidArgumentException'으로 인해 응용 프로그램을 종료합니다. 이유 : '응용 프로그램이 대상 에 모달보기 컨트롤러를 표시하려고했습니다.'.. – dickfala

관련 문제