작업 시트가 iPad에서 작동하지 않음
액션을 사용합니다.내 신청서에 써넣어요.제 아이폰에서는 작동하지만 아이패드 시뮬레이터에서는 작동하지 않습니다.
이건 내 코드야:
@IBAction func dialog(sender: AnyObject) {
let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .ActionSheet)
let deleteAction = UIAlertAction(title: "Delete", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
println("Filtre Deleted")
})
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
(alert: UIAlertAction!) -> Void in
println("Cancelled")
})
optionMenu.addAction(deleteAction)
optionMenu.addAction(cancelAction)
self.presentViewController(optionMenu, animated: true, completion: nil)
}
그리고 내 실수는:
'NSGenericException' 예외로 인해 앱을 종료합니다. 이유: '응용 프로그램이 UIAertControllerStyleAction 스타일의 UIAertController()를 제공했습니다.Sheet. 이 스타일을 가진 UIAlert 컨트롤러의 모달 프레젠테이션 스타일은 UIModal Presentation Popover입니다.알림 컨트롤러의 팝업 표시 컨트롤러를 통해 이 팝업에 대한 위치 정보를 제공해야 합니다.sourceView 및 sourceRect 또는 barButtonItem을 제공해야 합니다.알림 컨트롤러를 표시할 때 이 정보를 알 수 없는 경우 UIPopoverPresentationControllerDelegate 메서드 -prepareForPopoverPresentation'에서 제공할 수 있습니다.
iPad의 UIPopover Presentation Controller는 오류에 나와 있듯이 iPad에서는 UIPopover Presentation Controller이므로 옵션 메뉴를 표시하기 직전에 소스 보기 또는 버튼을 제공해야 합니다.이것은 작업 시트가 사용자에게 시작 위치를 알려주는 단추를 가리킨다는 것을 의미합니다.
예를 들어 오른쪽 탐색 모음 항목을 눌러 옵션 메뉴를 표시하는 경우입니다.다음과 같은 작업을 수행할 수 있습니다.
optionMenu.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem
self.presentViewController(optionMenu, animated: true, completion: nil)
또는 다음과 같은 보기를 설정할 수 있습니다. (이 두 가지 중 하나만 필요합니다.)
optionMenu.popoverPresentationController?.sourceView = yourView
self.presentViewController(optionMenu, animated: true, completion: nil)
또한 작업 시트 대신 UIAlertControllerStyle을 Alert로 변경하면 이를 지정할 필요가 없습니다.저는 당신이 그것을 알아냈을 것이라고 확신하지만, 저는 이 페이지를 접하는 모든 사람들을 돕고 싶었습니다.
저도 같은 문제입니다.저는 전화기에서 잘 작동하는 UIALert 컨트롤러를 가지고 있었지만, 아이패드에서는 작동하지 않았습니다.표 보기에서 셀을 누르면 시트가 팝업됩니다.
Swift 3의 경우, 제시하기 직전에 코드 3줄을 추가했습니다.
...
sheet.popoverPresentationController?.sourceView = self.view
sheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection()
sheet.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
self.present(sheet, animated: true, completion: nil)
스위프트 3
앞에서 말한 것처럼, 당신은 iPAD의 특정 지점에 표시되도록 UIAertController를 구성해야 합니다.
탐색 모음의 예:
// 1
let optionMenu = UIAlertController(title: nil, message: "Choose an option", preferredStyle: .actionSheet)
// 2
let deleteAction = UIAlertAction(title: "Option 1", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
print("option 1 pressed")
})
let saveAction = UIAlertAction(title: "Option 2", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
print("option 2 pressed")
})
//
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
// 4
optionMenu.addAction(deleteAction)
optionMenu.addAction(saveAction)
optionMenu.addAction(cancelAction)
// 5
optionMenu.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem
self.present(optionMenu, animated: true) {
print("option menu presented")
}
화살표 없이 중앙에 표시하려면 [Swift 3+]:
if let popoverController = optionMenu.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
self.present(optionMenu, animated: true, completion: nil)
제시하기 전에 다음 용어로 설명을 추가합니다.
optionMenu.popoverPresentationController.sourceView = self.view;
optionMenu.popoverPresentationController.sourceRect =
CGRectMake(0,0,1.0,1.0);
@IBAction func dialog(sender: AnyObject) {
...
optionMenu.popoverPresentationController.sourceView = self.view;
optionMenu.popoverPresentationController.sourceRect = CGRectMake(0,0,1.0,1.0);
self.presentViewController(optionMenu, animated: true, completion: nil)
}
그것은 잘 될 것입니다.
IB의 소스 뷰를 앱의 관련 변수에 연결하지 않은 경우에도 이 오류가 발생할 수 있습니다.
작업을 관리하기 위해 이 패키지를 수행했습니다.iPhone, iPad 및 Mac의 시트 및 포오버. https://github.com/AndreaMiotto/ActionOver
당신은 이것을 ipad에 추가해야 합니다.
alertControler.popoverPresentationController?.sourceView = self.view
팝업이 컨트롤러 위에 표시됩니다.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, 너비: 0, 높이: 0)
언급URL : https://stackoverflow.com/questions/28089898/actionsheet-not-working-ipad
'programing' 카테고리의 다른 글
| Android 웹 보기 느림 (0) | 2023.08.17 |
|---|---|
| 양호한 C 문자열 라이브러리 (0) | 2023.08.12 |
| MYSQL에서 매월 최대 날짜를 가져오는 방법 (0) | 2023.08.12 |
| Spring Scheduled 주석에서 고정 속도와 고정 지연의 차이점은 무엇입니까? (0) | 2023.08.12 |
| 당신은 PHP의 클래스 내에서 정적 상수를 사용할 수 있습니까? (0) | 2023.08.12 |