我有一个分组样式表视图。而我想要实现的是从手指着陆屏幕的那一刻起突出其细胞。但是实际上做的是在触及时突出显示。这是迄今为止我所拥有的。如何向UITableViewCell添加触摸识别器?
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我画的细胞背景颜色我想和油漆它放回功能的完成封闭,由攻上这些细胞触发。但是它并没有成为一个好用户,因为用户不知道,如果按钮被启用或者没有启动,
其实你想做什么? –
我希望我的单元格在我触摸它时立即突出显示(选中),但现在只有当我将手指从其上移开时才会突出显示(触摸)。 –
你会分享演示吗?如果你不介意我会检查它,并用解决方案返回给你 –