本文介绍了如何使用Eureka Forms中的行呈现viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于Eureka用于创建包含不同数据类型的新记录,其中一个是 MediaPicker
,我想知道如何呈现其viewController。
哪一排可以完成这项工作? PushRow
或 ButtonRow
这是我的班级我在哪里尝试创建这个。
import UIKit
import MediaPlayer
import Eureka
公共决赛班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)
})
}
}
公共类AddMusicViewController:MPMediaPickerController,MPMediaPickerControllerDelegate {
var musicPicker:MPMediaPickerController!
public var row:RowOf< MPMediaItemCollection>!
public var completionCallback:((UIViewController) - >())?
public override func viewDidLoad(){
super.viewDidLoad()
//加载视图后进行任何其他设置。
//为tableView设置部分/行
addMusic()
}
//初始化musicPicker并自定义它
func addMusic(){
musicPicker = MPMediaPickerController.self(mediaTypes:.Music)
musicPicker.delegate = self
musicPicker.allowsPickingMultipleItems = true
view.addSubview(musicPicker.view)
}
//选择后,将数据存储到数组
public func mediaPicker(mediaPicker:MPMediaPickerController,didPickMediaItems mediaItemCollection:MPMediaItemCollection){
musicTemp = nil
musicTemp = mediaItemCollection
如果musicTemp == nil {
noMusic = true
} else {
noMusic = false
}
completionCallback?(self)
}
//取消mediaPickerController
public func mediaPickerDidCancel(mediaPicker:MPMediaPickerController){
//如果用户取消了
,则取消选择器noMusic = true
completionCallback?(self)
}
}
以下是我所面临的错误。
解决方案
虽然这是一个通用的问题,但我的要求是使用 MPMediaPickerController
。 / p>
以下是我的设置。
import UIKit
import MediaPlayer
导入Eureka
// MusicRow
公共最终类MusicRow:SelectorRow< MPMediaItemCollection,PushSelectorCell< MPMediaItemCollection> ;, AddMusicViewController> ;, RowType {
public required init(tag:String?){
super.init(tag:tag)
presentationMode = .Show(controllerProvider:ControllerProvider.Callback {return AddMusicViewContro ller(){_ in}},completionCallback:{vc in vc.navigationController?.popViewControllerAnimated(true)})
displayValueFor = {
guard var musicTitle = $ 0 else {return}
musicTitle = musicTemp!
let representativeItem = musicTitle.representativeItem
print(representativeItem = \(representativeItem))
let representativeItemTitle = representativeItem?.title
return\(representativeItemTitle)
}
}
}
// MusicViewController
公共类AddMusicViewController:UIViewController,TypedRowControllerType,MPMediaPickerControllerDelegate {
public var row :RowOf< MPMediaItemCollection>!
public var completionCallback:((UIViewController) - >())?
lazy var musicPicker:MPMediaPickerController = {[unowned self] in
let mediaPicker = MPMediaPickerController.self(mediaTypes:.Music)
return mediaPicker
}()
必需public init?(编码器aDecoder:NSCoder){
super.init(编码器:aDecoder)
}
公共覆盖init(nibName nibNameOrNil: String?,bundle nibBundleOrNil:NSBundle?){
super.init(nibName:nil,bundle:nil)
}
方便公共init(_ callback:(UIViewController) - >()){
self.init(nibName:nil,bundle:nil)
completionCallback = callback
}
public override func viewDidLoad(){
super.viewDidLoad()
view.addSubview(musicPicker.view)
musicPicker.delegate = self
musicPicker.allowsPickingMultipleItems = true
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:,st yle:.Plain,target:nil,action:nil)
}
//选择后,将数据存储到临时变量
public func mediaPicker(mediaPicker:MPMediaPickerController, didPickMediaItems mediaItemCollection:MPMediaItemCollection){
musicTemp = nil
musicTemp = mediaItemCollection
if musicTemp == nil {
noMusic = true
} else {
noMusic = false
row.value? = musicTemp!
}
completionCallback?(self)
}
//取消mediaPickerController
public func mediaPickerDidCancel(mediaPicker:MPMediaPickerController){
//如果用户取消了
,则取消选择器noMusic = true
completionCallback?(self)
}
}
我相信,根据任何人的个人要求调整它并不困难!
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.
import UIKit
import MediaPlayer
import Eureka
// MusicRow
public final class MusicRow : SelectorRow<MPMediaItemCollection, PushSelectorCell<MPMediaItemCollection>, AddMusicViewController>, 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) })
displayValueFor = {
guard var musicTitle = $0 else { return "" }
musicTitle = musicTemp!
let representativeItem = musicTitle.representativeItem
print("representativeItem = \(representativeItem)")
let representativeItemTitle = representativeItem?.title
return "\(representativeItemTitle)"
}
}
}
// MusicViewController
public class AddMusicViewController : UIViewController, TypedRowControllerType, MPMediaPickerControllerDelegate {
public var row: RowOf<MPMediaItemCollection>!
public var completionCallback : ((UIViewController) -> ())?
lazy var musicPicker : MPMediaPickerController = { [unowned self] in
let mediaPicker = MPMediaPickerController.self(mediaTypes:.Music)
return mediaPicker
}()
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nil, bundle: nil)
}
convenience public init(_ callback: (UIViewController) -> ()){
self.init(nibName: nil, bundle: nil)
completionCallback = callback
}
public override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(musicPicker.view)
musicPicker.delegate = self
musicPicker.allowsPickingMultipleItems = true
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
}
// After selection, store the data into a temporary variable
public func mediaPicker(mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
musicTemp = nil
musicTemp = mediaItemCollection
if musicTemp == nil {
noMusic = true
} else {
noMusic = false
row.value? = musicTemp!
}
completionCallback?(self)
}
// Cancel mediaPickerController
public func mediaPickerDidCancel(mediaPicker: MPMediaPickerController){
// Dismiss the picker if the user canceled
noMusic = true
completionCallback?(self)
}
}
I believe, it isn't hard to tweak it to anyone's personal requirements!
这篇关于如何使用Eureka Forms中的行呈现viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!