gpt4 book ai didi

ios - 如何将 json 数据传递给可折叠标题 TableView Controller

转载 作者:搜寻专家 更新时间:2023-11-01 07:13:56 25 4
gpt4 key购买 nike

我试了很多次都没用。

错误:

/Users/admin/Desktop/Bkk 2/bkk/OfferDetailViewController.swift:93:55: Cannot convert value of type '[Deal]' to expected argument type '[String]'

代码:

var deals = [Deal]()

var sections = [Section]()


sections = [
Section(name: "Select from option", items:deals),
Section(name: "merchant Details", items: [ForyouString, "iPad Air 2", "iPad mini 4", "Accessories"]),
Section(name: "How to use deals", items: ["iPhone 6s", "iPhone 6", "iPhone SE", "Accessories"]),
Section(name: "things to remember", items: ["exchange for cash not allowed"]),
Section(name: "Cancelation policy", items: ["Once bought cannot exchange"]),
Section(name: "what you get", items: ["Capacity buliding courses"])
]
func parseDeals(data: NSData) -> [Deal]{
var deals = [Deal]()

do{
let jsonresult = try JSONSerialization.jsonObject(with: data as Data, options: .mutableContainers) as? NSDictionary

let jsondeals = jsonresult?["deals"] as! [AnyObject]
for jsondeal in jsondeals{
let deal = Deal()
deal.deals_name = jsondeal["deals_name"] as! String
deal.image_url = jsondeal["image_url"] as! String
deal.actual_price = jsondeal["actual_price"] as! String
deal.discounted_price = jsondeal["discounted_price"] as! String
deal.discounted_percentage = jsondeal["discounted_percentage"] as! String
deal.max_purchase_per_customer = jsondeal["max_purchase_per_customer"] as! String
deal.qty_available = jsondeal["qty_available"] as! String
deal.valid_from = jsondeal["valid_from"] as! String
deal.valid_to = jsondeal["valid_to"] as! String
deals.append(deal)

}
}
catch{
print(error)

}
return deals
}


func back(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}

func buttonClicked(){

print("button Clicked")

}
func showLocalError(errorMsg: String,title:String = "Oops!") {
let appearance = SCLAlertView.SCLAppearance(
showCloseButton: true
)
let alertView = SCLAlertView(appearance: appearance)
alertView.showWarning(title, subTitle: errorMsg)
}


func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].items.count
}

//
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell? ?? UITableViewCell(style: .default, reuseIdentifier: "cell")

cell.textLabel?.text = sections[(indexPath as NSIndexPath).section].items[(indexPath as NSIndexPath).row]
return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return sections[(indexPath as NSIndexPath).section].collapsed! ? 0 : 44.0
}

它在部分显示错误,当我传递交易时它显示错误,我找不到我做错的地方,我需要如何在部分传递交易数组。

最佳答案

错误信息很清楚:

在行中

Section(name: "Select from option", items:deals)

您传递的是 Deal 对象数组作为第二个参数,而不是预期的 String 数组,Section 初始值设定项是

init(name: String, items: [String])

关于ios - 如何将 json 数据传递给可折叠标题 TableView Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43320292/

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