簡體   English   中英

如何在兩行UITableview之間添加UIView

[英]How to Add UIView between two row of UITableview

在此處輸入圖片說明 我知道tableview的頁眉和頁腳,但是我想在Objective-c的tableview行之間添加UIView。 和uiview也有三個按鈕。 但是怎么可能。 任何人都可以幫助我。

您不能在UITableView兩行或單元格之間添加UIView 您需要自定義單元格。 並且在將數據填充到UITableView的數據源時,您需要在UITableViewcellForRowAtIndexPath方法中需要匹配的某種指示,並根據條件需要顯示數據單元格或自定義UIView (已在自定義單元格中)。

每個UITableViewCell都是UIView類的子級。 因此,實際上,您所有的單元都是UIView,您可以按任何需要的方式對其進行自定義。

因此,您要使用自定義單元格。 為它創建一個模型類,根據需要自定義它。

假設我有一個UIView,並且正在具有TableView的Controller類中創建其對象:

 var obj_ProfileView : UserProfileView!

在ViewDidLoad方法中:

self.obj_ProfileView = Bundle.main.loadNibNamed("UserProfileView", owner: self, options: nil)![0] as! UserProfileView

然后在TableViewFooter方法中:

 func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
    {
        if section == 0
        {
            //Do as per your requirements
            return 184.0
        }
        else
        {
            //Do as per your requirements
            return 45.0
        }
    }

    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
    {
        if section == 0
        {
            return obj_ProfileView
        }
        else{
            return nil
        }
    }

暫無
暫無

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

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