如何将降落识别器添加到UITableViewCell

如何将降落识别器添加到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中,我将单元格背景绘制为所需的颜色,并将其绘制回由点击这些单元格触发的函数的完成闭包中。但这并不能成为一个好的用户体验,因为用户在拿起手指之前不知道按钮是否启用。
澄清一下,我想达到的目标,
ios - 如何将降落识别器添加到UITableViewCell?-LMLPHP
我所拥有的ios - 如何将降落识别器添加到UITableViewCell?-LMLPHP

最佳答案

我想你只是把你的手机选择风格设为无。

cell.selectionStyle = UITableViewCellSelectionStyle.default

当您选择单元格时,它的默认选择功能工作,请查找HERE in video
你也可以在视频中看到我的代码。我什么也不做只是把这一行写进cellforrowat方法

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

10-10 14:26