chenzhao

  • java
  • iOS
  • IT
知识积累
不积跬步无以至千里
  1. 首页
  2. iOS
  3. 正文

UIActionSheet 在ipad中弹不出的问题

2016年 12月 2日 84点热度 0人点赞 0条评论

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

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 的那个


    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) { 
//            
//        }
//    }
标签: 暂无
最后更新:2022年 11月 11日

陈昭

IT 程序员

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

COPYRIGHT © 2022 chenzhao. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang