簡體   English   中英

自定義ios tableview單元不起作用

[英]custom ios tableview cell not working

我有一個自定義的tableview單元格,如果單擊該單元格,則應將其展開,如果未單擊,則該單元格不應被展開。

還有一個自定義視圖,如果單擊該單元格,我希望增加該自定義視圖的高度,如果未單擊該單元格,則它應該是某個高度。下面的代碼在cellForRowAt中設置

 if TableView.rowHeight == 126 {

            cell.CustomView = UIView(frame: CGRect(x: 7, y: 8, width: 359, height: 20))

            return cell
        }
        else{

        }

但是我設置的更改視圖高度的代碼不起作用,並且我不確定從那里去哪里

當未單擊該單元格時,這就是我的自定義視圖的外觀: 在此處輸入圖片說明

單擊單元格時,自定義視圖如下所示: 在此處輸入圖片說明

如您所見,我的問題是未單擊該單元格時,視圖的底部是一條直線,但是當單擊該單元格時,底部是圓形的。 我希望在未單擊單元格時也對視圖進行四舍五入。

調用beginUpdatesendUpdates以強制tableView更新高度

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // new row selected
    self.selectedIndex = indexPath
    tableView.beginUpdates()
    tableView.endUpdates()
}

也可以看看

在下面添加代碼。 希望這對你有幫助。

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

        //performSegue(withIdentifier: "toDetail", sender: self)
        self.isExpanded = true
        self.selectedIndex = indexPath
        tableView.beginUpdates()
        tableView.endUpdates()
        self.isExpanded = false
    }
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {

        self.selectedIndex = IndexPath()
        tableView.beginUpdates()
        tableView.endUpdates()
    }

禮貌:@JožeWs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM