Reputation: 137
I am using the following code. However when the image picker page comes I get "Photo" instead of "Media Picker" always:
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func importLibButtonAction(_ sender: UIButton) {
let file = UIImagePickerController()
file.delegate = self
file.navigationItem.title = "Media Picker"
file.sourceType = UIImagePickerControllerSourceType.photoLibrary
file.mediaTypes = ["public.image", "public.movie"]
file.videoMaximumDuration = 5.0
file.allowsEditing = false
self.present(file, animated: true)
{
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
self.dismiss(animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
What's possibly wrong here and how do I correct this? I want the imagepicker page to have custom title.
Using navigation controller for the same didn't work too:
navigationController?.pushViewController(file, animated: true)
Upvotes: 0
Views: 664
Reputation: 61
You can implement UINavigationControllerDelegate method willShow. You need to check viewControllers.count in navigation controller for showing actual Album name when choosing one (Camera Roll, Moments, etc).
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
if navigationController.viewControllers.count == 1 {
viewController.navigationItem.title = "Media Picker"
}
}
Upvotes: 1