gpt4 book ai didi

ios - UISearchController 拿错了项目

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

这是我的代码,我在搜索之前点击 + 它给出了正确的产品。但问题是搜索后,它给出了以前的产品而不是正确的产品  my table view

搜索 UISearchController 后查找 self.tableView搜索工作正常

enter image description here

表格 View

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


// Configure the cell...
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "MasterViewCell"

guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? MasterViewCell else {
fatalError("The dequeued cell is not an instance of OutletViewCell.")
}

// Fetches the appropriate meal for the data source layout.

var product = products[indexPath.row]
if isFiltering {
product = filteredProducts[indexPath.row]
} else {
product = products[indexPath.row]
}



cell.productName.text = product.productDescription
cell.availQty.text = "Avail. Qty:" + String(product.stock)
cell.productPrice.text = "Price: " + String(product.defaultSellPrice)
cell.addItem.tag = indexPath.row
cell.addItem.addTarget(self, action: #selector(buttonTapped(button:)), for: .touchUpInside)

orderDetails.forEach { detail in
// print(word.price)
if detail.key == product.id {
cell.AddedQty.text = "Qty :" + String(detail.value.qty)
}

}

return cell
}

这里是buttonTapped函数

    @objc func buttonTapped(button: UIButton) {
// print("Button pressed " + String(button.tag))
let product=products[button.tag]
print(product.productDescription)
showAlert(product: product)

}

最佳答案

在你的buttonTapped函数中,你还需要检查数据是否被过滤

  @objc func buttonTapped(button: UIButton) {
let productData = isFiltering ? filteredProducts[indexPath.row] : products[indexPath.row]
showAlert(product: productData)
}

关于ios - UISearchController 拿错了项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59262052/

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