2017-02-14 90 views
0

我有一個事務表查看不同類型的費用,擴大後顯示更多的細節,當選擇。擴大tableview單元格數據被選中時被覆蓋

但是,當這種情況發生時,細節似乎被覆蓋。我可以看到它閃光,有時它確實得到填充。文本框會正確填充。我一直在試圖調試一段時間,但不知道如何解決這個問題。

這是我目前的執行:

// MARK: Tableview 
extension TransactionViewController: UITableViewDelegate, UITableViewDataSource { 
    // MARK: - Table View 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: "CardCell", for: indexPath) as! CardTableViewCell 

     cell.delegate = self 

     var isDetailHidden = true 
     if indexPath.row == rowSelected { 
      isDetailHidden = false 
     } 
     let transaction = transactionList[indexPath.row] 
     cell.configureCell(transaction: transaction, isDetailHidden: isDetailHidden) 

     return cell 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return transactionList.count 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

    if indexPath.row == rowSelected { 
     // don't refresh and set again. 
     return 
    } 

    rowSelected = indexPath.row 
    transactionBeingEdited = transactionList[indexPath.row] 

    transactionTableView.setContentOffset(CGPoint(x: 0, y: rowSelected! * 76), animated: true) 

    let cell = tableView.dequeueReusableCell(withIdentifier: "CardCell", for: indexPath) as! CardTableViewCell 

    cell.delegate = self 
    cell.configureDetailCell() 
    transactionTableView.reloadData() 
} 

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 

     let transaction = transactionList[indexPath.row] 
     coreDataManager.deleteTransaction(transaction: transaction) 
    } 

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

     if indexPath.row != rowSelected { 
      return 76.5 
     } else { 
      return 323 
     } 
    } 

在細節部分的變量是使用庫下拉框。我已經在UITableViewCell類中配置了它。設置下拉方法發生在awakefromnib方法中。

private func setupBillDropDown() { 
     billDropDown.anchorView = bill 
     billDropDown.bottomOffset = CGPoint(x: 0, y: bill.bounds.height) 
     billDropDown.dataSource = TransactionType.list 

     // Action triggered on selection 
     billDropDown.selectionAction = { [unowned self] (index, item) in 
      self.bill.setTitle(item, for: .normal) 
      self.bill.setTitleColor(UIColor.white, for: .normal) 

      // Update transaction 
      if let transactionBeingEdited = self.delegate?.transactionBeingEdited { 
       transactionBeingEdited.type = item 
       self.coreDataManager.saveToCoreData() 
       self.coreDataManager.nc.post(name: .transactionBeingEdited, object: nil, userInfo: nil) 
      } 
     } 
    } 

在此先感謝。

回答

0

我想在func tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)中,通過加載表覆蓋已配置的單元格。試試這個:

FUNC的tableView(_的tableView:UITableView的,didSelectRowAt indexPath:IndexPath){

if indexPath.row == rowSelected { 
    // don't refresh and set again. 
    return 
} 

rowSelected = indexPath.row 
transactionBeingEdited = transactionList[indexPath.row] 

transactionTableView.setContentOffset(CGPoint(x: 0, y: rowSelected! * 76), animated: true) 

//let cell = tableView.dequeueReusableCell(withIdentifier: "CardCell", for: indexPath) as! CardTableViewCell 

let cell = tableView.cellForRow(at: indexPath) 
cell.configureDetailCell() 
tableView.reloadRows(at: [indexPath], with: .none) 

}

+0

不幸的是,這是行不通的。我認爲它與下拉字段有關,因爲細節部分中的兩個文本字段沒有被覆蓋。我試着將下拉方法移動到代碼中的不同位置,但是這並不能解決問題:( –

0

我想通了這個問題上,它確實花了幾個小時後......那是因爲我正在更新使用

insteaad的

bill.titleLabel!.text = transaction.type ?? "Select Bill" 

按鈕標題