首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAlertView问题

UIAlertView问题
EN

Stack Overflow用户
提问于 2016-11-23 18:39:35
回答 2查看 103关注 0票数 0

自从我更新到Xcode8后,我就开始遇到这个问题了,我不知道它是否是由于Xcode的一个bug造成的。

我有这个问题:this happens when I add this view to a tab bar

它应该是如此的if you do not tie it to anything it remains unchanged

问题不是我在下面添加的代码

代码语言:javascript
复制
import UIKit

类PhotoSelectViewController: UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate {

代码语言:javascript
复制
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var selectImageButton: UIButton!

weak var delegate: PhotoSelectViewControllerDelegate?

override func viewDidLoad() {
    super.viewDidLoad()
}

@IBAction func selectImageTapped(_ sender: AnyObject) {
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self

    let actionSheet = UIAlertController(title: "Choose image source", message: nil, preferredStyle: .actionSheet)

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

    let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default) { (_) in
        imagePicker.sourceType = .photoLibrary
        self.present(imagePicker, animated: true, completion: nil)
    }
    let cameraAction = UIAlertAction(title: "Camera", style: .default) { (_) in
        imagePicker.sourceType = .camera
        self.present(imagePicker, animated: true, completion: nil)
    }

    actionSheet.addAction(cancelAction)

    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
        actionSheet.addAction(photoLibraryAction)
    }
    if UIImagePickerController.isSourceTypeAvailable(.camera) {
        actionSheet.addAction(cameraAction)
    }

    self.present(actionSheet, animated: true, completion: nil)

    selectImageButton.setTitle("", for: .normal)

}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        imageView.image = image
        delegate?.photoSelectViewControllerSelectedImage(image: image)
    }
    dismiss(animated: true, completion: nil)
}

}

协议类:PhotoSelectViewControllerDelegate{ func photoSelectViewControllerSelectedImage(镜像: UIImage) }

EN

回答 2

Stack Overflow用户

发布于 2016-11-23 18:50:27

iOS 8中不推荐使用UIAlertView。

现在您需要使用UIAlertController:

代码语言:javascript
复制
    let alertController = UIAlertController(title: "Choose image source", message: "", preferredStyle: .actionSheet)

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { result in
        print("Destructive")
    }

    // Replace UIAlertActionStyle.Default by UIAlertActionStyle.default
    let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default) { result in
        print("OK")
    }

    alertController.addAction(cancelAction)
    alertController.addAction(photoLibraryAction)
    self.present(alertController, animated: true)

票数 1
EN

Stack Overflow用户

发布于 2016-11-23 19:08:56

UIAlertView已弃用。在iOS 8上使用preferredStyle为UIAlertControllerStyleAlert的UIAlertController,你可以这样做

代码语言:javascript
复制
let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40762106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档