Ich habe eine gruppierte Stil Tabellenansicht. Und was ich erreichen möchte, ist, seine Zelle von dem Moment an zu markieren, wenn der Finger auf einem Bildschirm landet. Aber was es tatsächlich macht, ist Hervorhebung, wenn es nachgebessert wird. Hier ist, was ich bisher habe.Wie fügt man der UITableViewCell einen Touchdown-Erkenner hinzu?
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
}
}
Also in meinem didSelectRowAt male ich Zellen Hintergrund zu einer Farbe, die ich will und male sie in einem Abschluss Schließung von Funktionen zurück, die durch das Klopfen auf diesen Zellen ausgelöst werden. Aber es macht keinen guten UX, weil der Benutzer nicht weiß, ob die Taste aktiviert ist oder nicht, bevor er den Finger hoch nimmt.
Um zu klären, was ich erreichen will, und was ich
Eigentlich was Sie tun möchten? –
Ich möchte meine Zelle markiert (ausgewählt) werden, sobald ich sie berühren, aber jetzt wird es nur hervorgehoben, wenn ich meinen Finger von ihm wegnehmen (retuschieren). –
Teilen Sie eine Demo? Wenn Sie dont Geist werde ich es überprüfen und zurück mit Lösung zu Ihnen zurück –