自从我更新到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。
问题不是我在下面添加的代码
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)
}}
协议类:PhotoSelectViewControllerDelegate{ func photoSelectViewControllerSelectedImage(镜像: UIImage) }
发布于 2016-11-23 18:50:27
iOS 8中不推荐使用UIAlertView。
现在您需要使用UIAlertController:
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)

发布于 2016-11-23 19:08:56
UIAlertView已弃用。在iOS 8上使用preferredStyle为UIAlertControllerStyleAlert的UIAlertController,你可以这样做
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)https://stackoverflow.com/questions/40762106
复制相似问题