gpt4 book ai didi

arrays - 将字符串复制到模型(Swift 3)

转载 作者:行者123 更新时间:2023-11-28 15:25:52 25 4
gpt4 key购买 nike

我的 PhotoModel 没有为 eventDate() 返回任何内容..

我已经设置好了

let newPhotos = PhotosModel()  // Create the instance
newPhotos.eventDate = item.event_date! // Set the parameter

在 didSelectItemAt 中,打印时返回前一个 View Controller 中的正确日期,但不会将其推送到 PhotoModel 字符串。

如果有人能为我指出正确的方向或展示需要做什么,那就太好了,谢谢。

View Controller :

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.row)

// Configure the cell
let item: CoverModel = feedItems[indexPath.row] as! CoverModel

let Storyboard = UIStoryboard(name: "Main", bundle: nil)
let DvC = Storyboard.instantiateViewController(withIdentifier: "DetailCollectionViewController") as! DetailCollectionViewController

print(item.event_date!)

let newPhotos = PhotosModel() // Create the instance
newPhotos.eventDate = item.event_date! // Set the parameter

print(newPhotos.eventDate)

self.navigationController?.pushViewController(DvC, animated: true)
}

照片模型:

protocol PhotosProtocol: class {
func itemsDownloaded(items: NSArray)
}

class PhotosModel: NSObject, URLSessionDataDelegate {
//properties
weak var delegate: PhotosProtocol!

var eventDate = String()
var data = Data()

func downloadItems() {
let urlPath: String = "http://www.britanniaclub.co.uk/app_calls/britalbum.php?eventdate=\(eventDate)"
let url: URL = URL(string: urlPath)!
print("the event date is \(eventDate)")
print("the urlPath is \(urlPath)")

let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)

let task = defaultSession.dataTask(with: url) { (data, response, error) in
if error != nil {
print("Failed to download data")
}else {
print("Event Data downloaded")
self.parseJSON(data!)
}
}

task.resume()
}

输出是:

2017-07-14

the event date is

the urlPath is http://www.britanniaclub.co.uk/app_calls/britalbum.php?eventdate=

事件数据下载

最佳答案

我的猜测是您没有将 newPhotos 分配给 DetailCollectionViewController 的任何属性。在推送此 View Controller 之前,您必须这样做。

关于arrays - 将字符串复制到模型(Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45258358/

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