![](/img/trans.png)
[英]How to add a separator cell/uiview between cells in a UITableView?
[英]How to Add UIView between two row of UITableview
您不能在UITableView
兩行或單元格之間添加UIView
。 您需要自定義單元格。 並且在將數據填充到UITableView
的數據源時,您需要在UITableView
的cellForRowAtIndexPath
方法中需要匹配的某種指示,並根據條件需要顯示數據單元格或自定義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.