Home > Mobile >  How to open particular view controller after selecting a audio file in swift
How to open particular view controller after selecting a audio file in swift

Time:11-26

I want to open particular view controller after selecting a audio file from document directory. I am doing this -:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "PlaySoundsViewController") as! PlaySoundsViewController
    vc.recordedAudioURL = url
    self.navigationController?.pushViewController(vc, animated: false)
}

and open document directory using this -:

@IBAction func startBtn(_ sender: UIButton) {
    let pickerController = UIDocumentPickerViewController(documentTypes: ["public.audio"], in: .import)
    pickerController.delegate = self
    pickerController.modalPresentationStyle = .fullScreen
    self.present(pickerController, animated: true, completion: nil)
}

CodePudding user response:

you have to present the view controller

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "PlaySoundsViewController") as! PlaySoundsViewController
    vc.recordedAudioURL = url
    self.present(vc, animated: true, completion: nil)
}
  • Related