[英]How to Add UIView between two row of UITableview
You can not add UIView
in between two row or cell of UITableView
. 您不能在UITableView
两行或单元格之间添加UIView
。 You need to customise your cells. 您需要自定义单元格。 And while filling data to your datasource of UITableView
you need some kind of indications which you need to match in your cellForRowAtIndexPath
method of UITableView
and based on condition you need to show your data cell or custom UIView
which is already in your custom cell. 并且在将数据填充到UITableView
的数据源时,您需要在UITableView
的cellForRowAtIndexPath
方法中需要匹配的某种指示,并根据条件需要显示数据单元格或自定义UIView
(已在自定义单元格中)。
Every UITableViewCell
is a child of UIView
class. 每个UITableViewCell
都是UIView
类的子级。 So in effect all your cells are UIViews which you can customize in any way you want. 因此,实际上,您所有的单元都是UIView,您可以按任何需要的方式对其进行自定义。
So what you want to do is use custom cell. 因此,您要使用自定义单元格。 Create a model class for it, customize it as you want. 为它创建一个模型类,根据需要自定义它。
Suppose I have a UIView and I am creating its object in Controller class in which I have TableView: 假设我有一个UIView,并且正在具有TableView的Controller类中创建其对象:
var obj_ProfileView : UserProfileView!
In ViewDidLoad Method: 在ViewDidLoad方法中:
self.obj_ProfileView = Bundle.main.loadNibNamed("UserProfileView", owner: self, options: nil)![0] as! UserProfileView
Then In TableViewFooter Method: 然后在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.