2016-11-23 2 views
0

У меня возникла эта проблема, так как я обновился до Xcode 8. Я не знаю, может ли она зависеть именно от ошибки Xcode.Проблемы с UIAlertView

У меня есть эта проблема: 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: класс { функ photoSelectViewControllerSelectedImage (изображение: пользовательский интерфейс) Изображение) }

+0

попробовать дать ему ширину –

+1

по умолчанию Не могли бы вы показать, как вы добавили предупреждение? – GoodSp33d

ответ

1

UIAlertView осуждается в прошивке 8.

Теперь вам нужно использовать 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) 

enter image description here

+1

Устаревший в iOS 8. – Sahil

+0

Upvoted. Вы можете сделать это немного приятнее для чтения, используя трейлинг-закрытия и тип вывода. Я обновил ваш ответ, если вы не возражаете. – crashoverride777

+0

Также ваши свойства должны начинаться с небольших букв – crashoverride777

1

UIAlertView устарела. Использование UIAlertController с preferredStyle из UIAlertControllerStyleAlert вместо КСН 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) 
Смежные вопросы