gpt4 book ai didi

ios - 如何向 UITableViewCell 添加触摸识别器?

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

我有一个分组样式 TableView 。我想要实现的是从手指落在屏幕上的那一刻起突出显示它的单元格。但它实际上做的是在润色时突出显示。这是我目前所拥有的。

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = labels[indexPath.section][indexPath.row]
cellSetup(cell: cell)
return cell
}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.prepareDisclosureIndicator()
}

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel?.font = header.textLabel?.font.withSize(12)
header.textLabel?.textColor = ColorConstants.symbolsColor
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 {
print("\(indexPath.row) didSelectRowAt")
}
let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
selectedCell.backgroundColor = ColorConstants.onTapColor
switch indexPath.row {
case 1:
let firstActivityItem =
let secondActivityItem : NSURL = NSURL(string: "http://aspetica.sooprun.com")!
// If you want to put an image

let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, secondActivityItem], applicationActivities: nil)

activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)

// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivityType.postToWeibo,
UIActivityType.print,
UIActivityType.assignToContact,
UIActivityType.saveToCameraRoll,
UIActivityType.addToReadingList,
UIActivityType.postToFlickr,
UIActivityType.postToVimeo,
UIActivityType.postToTencentWeibo
]

self.present(activityViewController, animated: true, completion: {
selectedCell.backgroundColor = .clear})
case 2:
let url = NSURL(string: "mailto:")
UIApplication.shared.open(url as! URL, options: [:], completionHandler: { (finish) in
selectedCell.backgroundColor = .clear})
// case 2:
// let appID = "959379869"
// if let checkURL = URL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=\(appID)&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8") {
// open(url: checkURL)
// } else {
// print("invalid url")
// }
default: break
}
}

func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
if indexPath.section == 0 {
return nil
} else {
let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
selectedCell.backgroundColor = ColorConstants.onTapColor
return indexPath
}
}

因此,在我的 didSelectRowAt 中,我将单元格背景绘制为我想要的颜色,然后在函数的完成闭包中将其重新绘制,这是通过点击这些单元格触发的。但这并不能提供良好的用户体验,因为用户在抬起手指之前不知道按钮是否启用。

澄清一下,我想要实现的目标, Here is what I need我有什么Here is what I have

最佳答案

我认为您只是将单元格选择样式设置为无。

cell.selectionStyle = UITableViewCellSelectionStyle.default

当您选择单元格时,它的默认选择功能起作用,找出HERE in video

你也可以在视频中看到我的代码。我什么都不做只是将这一行写入 cellforrowat 方法

关于ios - 如何向 UITableViewCell 添加触摸识别器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42223410/

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