As Eureka is used for creating a new record, which includes different datatypes, one being MediaPicker
, I'm wondering how to present its viewController.
Which row would do the job? PushRow
or ButtonRow
Here is my class where I try to create this.
import UIKit
import MediaPlayer
import Eureka
public final class MusicRow<T: Equatable> : SelectorRow<T, PushSelectorCell<T>, SelectorViewController<T>>, RowType {
public required init(tag: String?) {
super.init(tag: tag)
presentationMode = .Show(controllerProvider: ControllerProvider.Callback {
return AddMusicViewController(){ _ in }
}, completionCallback: { vc in
vc.navigationController?.popViewControllerAnimated(true)
})
}
}
public class AddMusicViewController: MPMediaPickerController, MPMediaPickerControllerDelegate {
var musicPicker: MPMediaPickerController!
public var row: RowOf<MPMediaItemCollection>!
public var completionCallback : ((UIViewController) -> ())?
public override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Setup sections/rows for tableView
addMusic()
}
// Initialize musicPicker and customize it
func addMusic() {
musicPicker = MPMediaPickerController.self(mediaTypes:.Music)
musicPicker.delegate = self
musicPicker.allowsPickingMultipleItems = true
view.addSubview(musicPicker.view)
}
// After selection, store the data into an array
public func mediaPicker(mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
musicTemp = nil
musicTemp = mediaItemCollection
if musicTemp == nil {
noMusic = true
} else {
noMusic = false
}
completionCallback?(self)
}
// Cancel mediaPickerController
public func mediaPickerDidCancel(mediaPicker: MPMediaPickerController){
// Dismiss the picker if the user canceled
noMusic = true
completionCallback?(self)
}
}
Below is the error that I face.
Although, this was a generic question, my requirement was to use a
MPMediaPickerController
.Below is my setup.
I believe, it isn't hard to tweak it to anyone's personal requirements!