UIActionSheet 在ipad中弹不出的问题

UIActionSheet 其实已经弃用,但是我们还在适配ios7 所以还在用着, 遇到过两次ipad 弹不出的问题, 然后时间久了会忘记,特此记录一下
创建用

1
2
3
4
5
6
7
8
9
let actionSheet = UIActionSheet()
actionSheet.delegate = self
actionSheet.actionSheetStyle = UIActionSheetStyle.default
actionSheet.addButton(withTitle: "取消")
actionSheet.addButton(withTitle: "从手机相册选择")
actionSheet.addButton(withTitle: "拍照")
actionSheet.cancelButtonIndex = 0
actionSheet.show(in: (controller?.view)!)

代理方法改用diss 的那个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
func actionSheet(_ actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {
if buttonIndex == 0{
return
}
let picker = UIImagePickerController()
if buttonIndex == 1{
picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
}else if buttonIndex == 2{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == false{
return
}
picker.sourceType = UIImagePickerControllerSourceType.camera
}
picker.delegate = self
picker.allowsEditing = true
self.findController().present(picker, animated: true) {
}
}
// 手机上ok 但是ipad 报错
// func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int){
// Getdevice.println("clickindex \(buttonIndex)")
// if buttonIndex == 0{
// return
// }
// let picker = UIImagePickerController()
//
// if buttonIndex == 1{
// picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
// }else if buttonIndex == 2{
// if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == false{
// return
// }
// picker.sourceType = UIImagePickerControllerSourceType.camera
// }
// picker.delegate = self
// picker.allowsEditing = true
// self.findController().present(picker, animated: true) {
//
// }
// }
Author

陈昭

Posted on

2016-12-02

Updated on

2021-12-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Kommentare

You forgot to set the shortname for Disqus. Please set it in _config.yml.