2017-02-14 9 views
0

私はグループスタイルのテーブルビューを持っています。そして、私が達成したいのは、指が画面に着く瞬間から細胞を強調することです。しかし実際には触れたときに強調表示されています。ここに私がこれまで持っているものがあります。タッチダウン認識機能を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に私は私が欲しい色にセルの背景を描画し、それらのセルをタップしてトリガされる機能の完了の閉鎖、それをバックペイント。しかし、彼は彼の指をかける前に、ボタンが有効かどうかわからないので、それは良いuxを作っていません。

Here is what I need 、私が達成したいものを、明らかにし、私はHere is what I have

+0

実際に何をしますか? –

+0

私はタッチするとすぐにセルをハイライト表示(選択)したいが、今は指を離して(タッチアップする)、強調表示されるようになる。 –

+1

デモを共有しますか?あなたが気にしないなら、私はそれをチェックし、解答であなたに戻ってきます –

答えて

1

私はあなただけのどれもあなたのセル選択のスタイルを設定すると考えています。

cell.selectionStyle = UITableViewCellSelectionStyle.default 

あなたはそのデフォルトの選択機能が働くセルを選択し、あなたはまた、ビデオで私のコードを見ることができますHERE in video

をご覧ください。私は何もしません。この行をcellforrowatメソッドに書きます。

+0

はい、そうです、私は選択スタイルを.noneに設定しました。今、私がそれを元に戻したとき、それは私が望むように機能します。しかし、どのようにしてこの選択の色を(カスタムカラーに)変更するのですか? { 強調表示された場合{ self.textLabel .textColor = UIColor.whiteColor他() } { self.textLabel .textColor = UIColor.blackColor() !setHighlighted(:ブールを、アニメーションブールを強調表示)FUNC –

+0

オーバーライド} } –

+0

このハイライトされた機能で、あなたは好きなように色を設定できます –

関連する問題