Arrays 正在覆盖餐车
我正在开发一个送货应用程序,但我的购物车有点问题。问题是:每次客户向购物车添加新项目时,购物车中的所有内容都使用最新项目的名称。它只会覆盖tableView对象,不会影响我的后端,所以我知道我导入了一些错误的内容 为了清楚起见,我有两个表:Product和Product Size,这是我通过JSON引入的: 产品文件:Arrays 正在覆盖餐车,arrays,json,swift,uitableview,Arrays,Json,Swift,Uitableview,我正在开发一个送货应用程序,但我的购物车有点问题。问题是:每次客户向购物车添加新项目时,购物车中的所有内容都使用最新项目的名称。它只会覆盖tableView对象,不会影响我的后端,所以我知道我导入了一些错误的内容 为了清楚起见,我有两个表:Product和Product Size,这是我通过JSON引入的: 产品文件: import Foundation import SwiftyJSON class Product { //This pulls the information per
import Foundation
import SwiftyJSON
class Product {
//This pulls the information per product. Edit information here and attach to each Restaurant cell.
var id: Int?
var name: String?
var short_description: String?
var image: String?
var type: String?
var size: String?
init(json: JSON) {
self.id = json["id"].int
self.name = json["name"].string
self.short_description = json["short_description"].string
self.image = json["image"].string
self.type = json["course"].string
}
}
产品尺寸:
import Foundation
import SwiftyJSON
class ProductSize {
//Label for product information
var price:Float?
var sizeId: Int?
var size: Int?
var product_id: Int?
init(json: JSON) {
self.price = json["price"].float
self.sizeId = json["id"].int
self.size = json["size"].int
self.product_id = json["product_id"].int
}
膳食从上一个视图控制器传递给我们:
override func prepare(对于segue:UIStoryboardSegue,发送方:Any?){
如果segue.identifier==“cartInfo”{
让控制器=segue.destination as!CartController
controller.product=产品
}
}
重复产品名称只意味着一件事:产品
不是一系列产品,而是一个产品,因此产品?.name
将不断出现。显然,您在上一个VC的Cart
类中设置product
变量,您应该将product
改为数组,并从上一个视图控制器附加到它
整个结构令人困惑,可能是您在
func tableView(u tableView:UITableView,cellForRowAt indexath:indexPath)中将cart
与product
混淆了
log to the console?它打印出Johnny'sRestuarant.CartItem,其中包含所有适当的数据,但是,当放入表对象时,这种情况会发生@carpsen90。动画块不应该在image.removeFromSuperview()之后关闭吗
有一个我没有复制的UIAlert。如何根据我以前的vc传递整个数组?您还没有显示要设置产品的部分