gpt4 book ai didi

swift - UIAlertView 问题

转载 作者:行者123 更新时间:2023-11-28 12:36:10 25 4
gpt4 key购买 nike

自从我更新到 Xcode 8 后我就开始遇到这个问题,我不知道它是否完全取决于 Xcode 错误。

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

应该是这样if you do not tie it to anything it remains unchanged .

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

import UIKit

类 PhotoSelectViewController:UIViewController、UINavigationControllerDelegate、UIImagePickerControllerDelegate {

@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)
}

协议(protocol) PhotoSelectViewControllerDelegate: 类 { func photoSelectViewControllerSelectedImage(图片:UIImage)

最佳答案

UIAlertView 已弃用。将 UIAlertController 与 preferredStyle 的 UIAlertControllerStyleAlert 一起使用在 iOS 8 上,你可以像下面那样做

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)

关于swift - UIAlertView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40762106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com