gpt4 book ai didi

ios - 如何在 TableView 中的行之间创建填充(间距)

转载 作者:可可西里 更新时间:2023-11-01 03:36:09 26 4
gpt4 key购买 nike

这不是重复的我阅读了与此相关的其他问题,但没有一个能给我我需要的东西,我正在创建一个带有自定义单元格的 TableView ,并且样式已分组。我在每行内有 1 个 ImageView,它比整行小。我需要创建多少个单元格是我从数据库中得到的东西,所以我不能使用静态单元格我需要在行之间留出间距,我不知道如何做这个。我尝试让单元格变大 (320,143) 并使其不可见,我设法做到了,但是当你按下图像外部时,它仍然像我按下单元格一样这几乎就是我想要实现的目标

first pic

但这是发生了什么:

second pic

我需要单元格为图像大小,但不同行之间有间距。我该怎么做?

最佳答案

有很多方法可以做到这一点,但我发现这是最简单易行的方法。

设置 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;
}

关于ios - 如何在 TableView 中的行之间创建填充(间距),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17490203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com