2017-08-10 16 views
1

TableViewは、ユーザーが各セル(UI:click)をクリックして展開できる場所です。テーブルビューで拡大表示されたスワイプ可能なセル

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchResultsUpdating { 
var selectedIndex: IndexPath? 
    var isExpended = false 

    func didExpandCell() { 
     self.isExpended = !isExpended 
     self.tableView.reloadRows(at: [selectedIndex!], with: .automatic) 

    } 
    @IBOutlet weak var tableView: UITableView! 
... 
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "wordCell", for: indexPath) as! CellController 
     if searchController.isActive { 
      cell.word.text = filtered[indexPath.row].word 
      cell.translation.text = filtered[indexPath.row].translation 
      cell.date.text = filtered[indexPath.row].fullDate 
      cell.exOne.text = filtered[indexPath.row].exOne 
      cell.exTwo.text = filtered[indexPath.row].exTwo 
     } else { 
      cell.word.text = words[indexPath.row].word 
      cell.translation.text = words[indexPath.row].translation 
      cell.date.text = words[indexPath.row].fullDate 
      cell.exOne.text = words[indexPath.row].exOne 
      cell.exTwo.text = words[indexPath.row].exTwo 
     } 
     return cell 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     self.selectedIndex = indexPath 
     self.didExpandCell() 
    } 

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     if isExpended && self.selectedIndex == indexPath { 
      return 180 
     } 
     return 70 
    } 
} 

また、すべての細胞はスワイプ可能な:これはそのためのコード(また、私は、このセルをレイアウトする.xibファイルを作成した)です。これはコードです:

func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? { 
     let edit = UITableViewRowAction(style: .normal, title: "Edit") { action, index in 
      print("Edit") 
     } 
     edit.backgroundColor = .blue 

     let delete = UITableViewRowAction(style: .normal, title: "Delete") { action, index in 
      print("Delete") 
     } 
     delete.backgroundColor = .red 

     return [delete, edit] 
    } 

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
     return true 
    } 

問題:click:私はセルをスワイプすると

、それは常に、これはスワイプした後、私のUIで、半分に消費します。私はそれらをスワイプするとCellを展開しないことは可能ですか?

+0

didSelectRowAtメソッドにデバッグポイントを置いて、スワイプすると、このmehodが呼び出されますか? – 3stud1ant3

+0

は、あなたの展開関数が不適切です、func didExpandCell()?たとえば、Cell1をクリックすると、isExpended = trueになり、Cellが開きます。再度、Cell2をクリックすると、isExpended = falseに設定され、Cell2は展開されません。 –

+0

いいえ、それはスワイプで呼ばれていません –

答えて

0

しかし、問題は私がセルの拡張バージョンの制約を設定していないということでした。そのため、このラベルはスワイプメニューで動いていました。今それは動作します。 すべての返信ありがとう!

+0

おそらくこれはあなたが興味を持っているかもしれないhttps://github.com/umarF/MultiSelectHeaders –

関連する問題