gpt4 book ai didi

ios - 通过 segue 发送的任何内容都返回 nil

转载 作者:行者123 更新时间:2023-11-29 01:44:27 25 4
gpt4 key购买 nike

下面是我的 segue 代码,但是当我尝试在另一个 View Controller 中访问它们时,所有变量都返回 nil。我什至添加了一个简单的字符串值来发送,它也返回 nil。

extension ViewController : MPMediaPickerControllerDelegate {
// must implement these, as there is no automatic dismissal

func mediaPicker(mediaPicker: MPMediaPickerController!, didPickMediaItems mediaItemCollection: MPMediaItemCollection!) {

let ViewControllerhost:ViewControllerHost = storyboard?.instantiateViewControllerWithIdentifier("HostViewController") as! ViewControllerHost

let representativeItem = mediaItemCollection.representativeItem
let title = representativeItem.title
let artistName = representativeItem.artist

segueInfo =
[ "representativeItem": representativeItem
, "title": title
, "artistName": artistName ]

var albumCover = "\(MPMediaItemArtwork())"
var songInfo = "\(MPMediaItem())"
var messageDict = [albumCover, songInfo]

//This sends across Album Artwork, Info, and the duration is sent from the Host view controller
let messageData = NSJSONSerialization.dataWithJSONObject(messageDict, options: NSJSONWritingOptions.PrettyPrinted, error: nil)

var error:NSError?

appDelegate.mpcHandler.session.sendData(messageData, toPeers: appDelegate.mpcHandler.session.connectedPeers, withMode: MCSessionSendDataMode.Unreliable, error: &error)

if error != nil{
println("error: \(error?.localizedDescription)")
}

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if let nextVC = segue.destinationViewController as? ViewControllerHost
, let sender = sender as? ViewController {
/*nextVC.representativeItem_ = sender.segueInfo["representativeItem"] as? MPMediaItem
nextVC.title_ = sender.segueInfo["title"] as! String
nextVC.artistName_ = sender.segueInfo["artistName"] as! String*/
nextVC.representativeItem_ = representativeItem
nextVC.title_ = title
nextVC.artistName_ = artistName
nextVC.test_ = test
}
}

dismissViewControllerAnimated(true, completion: {
self.navigationController?.pushViewController(ViewControllerhost, animated: true)
})
}








func mediaPickerDidCancel(mediaPicker: MPMediaPickerController!) {
self.dismissViewControllerAnimated(true, completion: nil)

}

最佳答案

我怀疑这个条件失败了:

if let nextVC = segue.destinationViewController as? ViewControllerHost, let sender = sender as? ViewController {

具体来说,if let sender = sender as? ViewController { 部分。

根据docs , sender 是触发 segue 的按钮或 View 。它不是 View Controller 本身,所以 if let sender = sender as? ViewController { 可能返回 false。

关于ios - 通过 segue 发送的任何内容都返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32084554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com