这不是重复我读了关于这个的其他问题,他们都没有给我我需要的东西,我正在创建一个带有自定义单元格的表视图,并且样式被分组。我在每行内部有一个ImageView,它比整行要小。我需要创建多少单元格,这是我从db得到的东西,所以我不能使用静态单元格,我需要在行之间有间距,我无法弄清楚如何做这个。我尝试制作单元格Bigger(320,143)并使其不可见,我设法做但当你按下图像外它仍然像我按下单元格 这几乎是我想要实现的目标
但是会发生这种情况:
我需要单元格为图像大小,但在不同行之间有间距。我怎么能这样做?
答案 0 :(得分:18)
有很多方法可以做到这一点,但我发现这是最简单,最简单的方法。
将UITableView
样式设置为已分组。然后有两个部分,每个部分只有一行。替换行中的图像。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//array is your db, here we just need how many they are
return [array count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//place your image to cell
}
- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//this is the space
return 50;
}
答案 1 :(得分:2)
只需将单元格的内容设为clearcolor,然后通过添加高度为自己填充。添加单元格的背景图像(或颜色),然后通过插入较短高度的新视图或标签来添加。
这样,您可以维护包含多个部分和多个行的表。
答案 2 :(得分:2)
你可以只用3行。
首先设置主视图的灰色,然后按照这些行。
cell.separatorInset = UIEdgeInsetsMake(20, 20, 20, 20);
cell.layer.borderWidth = 5;
cell.layer.borderColor = [UIColor whiteColor].CGColor;
答案 3 :(得分:1)
1.首先,您可以增加heightForRowAtIndexPath大小
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 150;
}
tableViewCell
上添加自定义视图。然后根据你想要的填充设置view.frame。答案 4 :(得分:0)
迅速5.1:
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 15
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 30
}