我正在开发一个简单的购物应用。在那里我使用UITableView列出产品,但是当我在特定单元格中选择列出的产品时," didSelectRowAt indexPath"方法没有被调用/触发,所以我尝试了长按UITableViewCell方法工作正常并且也正确触发但我不需要这个解决方案。
在产品列表页面中,我刚刚在导航栏中使用了UISegmentedControl,在UIView中使用了动态原型UITableView。即使我在这个页面中没有使用任何类型的UIGestures。
这个问题可能是重复的,已经在Stack Overflow中提出,但没有一个答案解决了我的问题。我需要继续工作UITableViewCell而不需要长按。
注意:我尝试关闭"延迟内容触动"在TableView中,我浏览Stack Overflow和Web,但我找不到任何解决方案。
更新
" cellForRowAt indexPath"代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ProductCell
let vendor = array_list_vendor[indexPath.row] as? String
let orgPrice = array_list_price[indexPath.row] as? Int
let starDealPrice = array_list_stardealPrice[indexPath.row] as? Int
let url = array_list_image[indexPath.row] as! String
cell.productTitle.text = array_list_title[indexPath.row] as? String
if url == "" {
cell.productImg.image = UIImage(named: "no-img")
}
else {
cell.productImg.image = nil
ImageLoader.sharedLoader.imageForUrl(urlString: (url), completionHandler:{(image: UIImage?, url: String) in
//cell.productImg.frame.width =
cell.productImg.image = image!
})
}
if vendor == "amazon" {
cell.sellerImg.image = UIImage(named: "prodicon-amazon")
}
else if vendor == "flipkart" {
cell.sellerImg.image = UIImage(named: "prodicon-flipkart")
}
else {
cell.sellerImg.image = UIImage(named: "prodicon-amazon")
}
cell.starDealImg.image = UIImage(named: "prodicon-stardeal")
let rupee = "\u{20B9}"
let text = String(format: "%@ %d", rupee, orgPrice!)
let linkTextWithColor = String(rupee)
let range = (text as NSString).range(of: linkTextWithColor!)
let attributedString = NSMutableAttributedString(string:text)
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.black , range: range)
//Seller price
cell.sellerPrice.attributedText = attributedString
let text1 = String(format: "%@ %d", rupee, starDealPrice!)
let linkTextWithColor1 = String(rupee)
let range1 = (text1 as NSString).range(of: linkTextWithColor1!)
let attributedString1 = NSMutableAttributedString(string:text1)
attributedString1.addAttribute(NSForegroundColorAttributeName, value: UIColor(red: 127.0/255.0, green: 63.0/255.0, blue: 152.0/255.0, alpha: 1.0) , range: range1) //Purple color
//Stardeal price
cell.starDealPrice.attributedText = attributedString1
let cashBack = orgPrice! - starDealPrice!
let text2 = String(format: "Save %@", rupee)
let linkTextWithColor2 = String(rupee)
let range2 = (text2 as NSString).range(of: linkTextWithColor2!)
let attributedString2 = NSMutableAttributedString(string:text2)
attributedString2.addAttribute(NSForegroundColorAttributeName, value: UIColor.white , range: range2)
let text3 = String(format: "%d", cashBack)
let linkTextWithColor3 = String(cashBack)
let range3 = (text3 as NSString).range(of: linkTextWithColor3)
let attributedString3 = NSMutableAttributedString(string:text3)
attributedString3.addAttribute(NSForegroundColorAttributeName, value: UIColor.white , range: range3)
//Attributed string with multiple words
attributedString2.append(attributedString3)
cell.productCashBack.attributedText = attributedString2
return cell
}