2016-10-11 4 views
0

보기 내에 UIButton이 있습니다. 있는 UIButton은iPad에서 UIAlertController 및 displayShareSheet가 충돌 함

enter image description here

같은 위치 나는있는 UIButton이이

enter image description here

과 같은 경고를 생성

@IBAction func shareButtonClicked(_ sender: AnyObject) { 
    Flurry.logEvent("Share button tapped"); 


    let textToShare = quotetext.text 

    // 1. 
    // Create and initialize a UIAlertController instance. 
    // 
    let alertController = UIAlertController(title: nil, 
              message: nil, 
              preferredStyle: .actionSheet) 

    // 2. 
    // Initialize the actions to show along with the alert. 
    // 
    let copyAction = UIAlertAction(title:"Copy Quote to clipboard", 
            style: .default) { (action) -> Void in 
            let pasteboard: UIPasteboard = UIPasteboard.general 
            pasteboard.string = self.quotetext.text; 
    } 

    let defaultAction = UIAlertAction(title:"Share Quote", 
             style: .default) { (action) -> Void in 
             // We have contents so display the share sheet 
             self.displayShareSheet(shareContent: textToShare) 

    } 

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in 
     // ... 
    } 

    // 3. 
    // Tell the alertController about the actions we want it 
    // to present. 
    // 
    alertController.addAction(copyAction) 
    alertController.addAction(defaultAction) 
    alertController.addAction(cancelAction) 


    // 4. 
    // Present the alert controller and associated actions. 
    // 
    self.present(alertController, animated: true, completion: nil) 

} 

를 클릭 할 때 트리거되는 @IBAction이 '견적 공유'를 선택하면 경고가 shareSheet를 불러옵니다.

이 @IBAction은 iPhone에서 작동하지만 iPad에서는 작동하지 않습니다. 오류 메시지가

'NSGenericException', 이유 : '응용 프로그램이 스타일 UIAlertControllerStyleActionSheet의 UIAlertController()을 선물했다. 이 스타일을 사용하는 UIAlertController의 modalPresentationStyle은 UIModalPresentationPopover입니다. 은 경고 컨트롤러의 popoverPresentationController를 통해이 팝업에 대한 위치 정보를 제공해야합니다. sourceView 및 sourceRect 또는 barButtonItem 중 하나를 으로 제공해야합니다. 알림 컨트롤러를 표시 할 때이 정보가 알 수없는 경우 인 경우 UIPopoverPresentationControllerDelegate 메서드 -prepareForPopoverPresentation에 제공 할 수 있습니다.

나는

//iPad 

    alertController.popoverPresentationController?.sourceView = viewBottom 
    alertController.popoverPresentationController?.sourceRect = viewBottom.bounds 
    alertController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down; 

처럼 작동하지 않습니다이 수정 뭔가를 시도하여이 문제를 해결하기 위해 노력했다. 경고가 'viewBottom'위에 잘못 배치되고 'defaultAction'버튼을 클릭하면 위의 오류 메시지와 함께 다시 충돌합니다.

나는 이것을 해결하기 위해 일종의 상실감이 있습니다. 누구든지 이것에 대해 조언을 해줄 수 있습니까? 나는

UIPopoverPresentationControllerDelegate 방법 -prepareForPopoverPresentation 사용하는 다양한 방법을 시도했습니다. "

내 코드에 있지만 성공하지 못했습니다. 이 점에 대해 조언 해 주셨습니다. 감사.

답변

0

교환이 라인 :

alertController.popoverPresentationController?.sourceView = viewBottom 
alertController.popoverPresentationController?.sourceRect = viewBottom.bounds 
alertController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down; 

과 :

if let button = sender as? UIButton { 
    alertController.popoverPresentationController?.sourceView = button 
    alertController.popoverPresentationController?.sourceRect = button.bounds 
} 

당신이해야합니다 또한 속성 설정하여 displayShareSheet 방법의 공유 시트의 popoverPresentationController. 아마도 거기에 사용할 수 있도록 UIButton을 매개 변수로 전달해야합니다.

+0

내 단추가 UIButton이고 UIBarButtonItem이 아니라고 생각하면 여전히 수정 될 예정입니까? 나는 그것을 위해 콘센트를 이미 가지고있다 - @IBOutlet weak var uploadBtn : UIButton! – user619804

+0

죄송합니다. 나는 그것이'UIBarButtonItem'이라고 가정했다. 'UIButton'에 대한 제 업데이트를보십시오. – rmaddy

+0

그 위대한 alertController 근무! 올바른 위치에 있습니다. '디스플레이 공유 시트'는 여전히 충돌하고 있습니다. 같은 방법으로 공유 시트를 어떻게 구성 할 수 있는지 잘 모르겠습니다. – user619804