Ios 在另一个UITableView单元格之后添加一个UITableView单元格
基本上,我有一个带有两种单元格类型的tableview。一个是包含从数组中提取的数字的单元格。第二个单元格只是作为间隔单元格,但可以包含信息。但是,我只看到了第二个单元格位于第一个单元格之后的解决方案,如果它的行等于0,或者如果它被切掉了 数字数组是[1,2,3,4,5,6,7],第一个单元格类型从中提取以显示每个数字 我正试图得到这样的东西: 手机一号:1 二号牢房 手机号码:2 二号牢房 手机号:3 二号牢房 手机号码:4 二号牢房 。。。等等 我想让太空舱在下一个太空舱后面,但我认为这没有意义Ios 在另一个UITableView单元格之后添加一个UITableView单元格,ios,arrays,swift,uitableview,Ios,Arrays,Swift,Uitableview,基本上,我有一个带有两种单元格类型的tableview。一个是包含从数组中提取的数字的单元格。第二个单元格只是作为间隔单元格,但可以包含信息。但是,我只看到了第二个单元格位于第一个单元格之后的解决方案,如果它的行等于0,或者如果它被切掉了 数字数组是[1,2,3,4,5,6,7],第一个单元格类型从中提取以显示每个数字 我正试图得到这样的东西: 手机一号:1 二号牢房 手机号码:2 二号牢房 手机号:3 二号牢房 手机号码:4 二号牢房 。。。等等 我想让太空舱在下一个太空舱后面,但我认为这没有
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let index = indexPath.row
if index >= 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsblock", for: indexPath ) as! DetailTBCell
return cell
}
else {
let spacecell = tableView.dequeueReusableCell(withIdentifier: "spacingcell", for: indexPath ) as! DetailSpaceTBCell
return spacecell
}
}
这将打印数组中的所有数字并显示它们,但第二个单元格根本不显示
我不知道该怎么做,也不知道如何让它工作。如果(索引%2)==0
|如果索引号是双精度的,请尝试放置第一个表格单元格,否则放置另一个表格单元格
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let index = indexPath.row
if (index % 2) == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsblock", for: indexPath ) as! DetailTBCell
return cell
}
else {
let spacecell = tableView.dequeueReusableCell(withIdentifier: "spacingcell", for: indexPath ) as! DetailSpaceTBCell
return spacecell
}
if(索引%2)==0
|如果索引号是双精度的,请尝试放置第一个tableCell,否则放置另一个tableCell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let index = indexPath.row
if (index % 2) == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsblock", for: indexPath ) as! DetailTBCell
return cell
}
else {
let spacecell = tableView.dequeueReusableCell(withIdentifier: "spacingcell", for: indexPath ) as! DetailSpaceTBCell
return spacecell
}
如果您注意到产品单元格需要显示在偶数位置,间隔单元格需要显示在奇数位置
`index >= 0 ` needs to replaced with `index % 2 == 0 `
此外,为了从产品数组中获取数据,您需要将索引除以2
let products = [1,2,3,4,5,6,7]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let index = indexPath.row
if index % 2 == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsblock", for: indexPath ) as! DetailTBCell
// Fetching data from array products defined above
let data = products[index / 2]
return cell
}
else {
let spacecell = tableView.dequeueReusableCell(withIdentifier: "spacingcell", for: indexPath ) as! DetailSpaceTBCell
return spacecell
}如果您注意到产品单元格需要显示在偶数位置,间隔单元格需要显示在奇数位置
`index >= 0 ` needs to replaced with `index % 2 == 0 `
此外,为了从产品数组中获取数据,您需要将索引除以2
let products = [1,2,3,4,5,6,7]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let index = indexPath.row
if index % 2 == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsblock", for: indexPath ) as! DetailTBCell
// Fetching data from array products defined above
let data = products[index / 2]
return cell
}
else {
let spacecell = tableView.dequeueReusableCell(withIdentifier: "spacingcell", for: indexPath ) as! DetailSpaceTBCell
return spacecell
}我也试过类似的方法。所发生的是,它和其他细胞一样,对第一种类型的细胞产生作用。所以它看起来像1个spacecell 3个spacecell 5个spacecell等等,因为它跳过了其余的。但是我试图得到一个结果,返回数组中的所有元素,并且数组中的每个数字后面都有间隔单元格。我尝试过类似的方法。所发生的是,它和其他细胞一样,对第一种类型的细胞产生作用。所以它看起来像1个spacecell 3个spacecell 5个spacecell等等,因为它跳过了其余的。但是,我试图实现一个结果,即返回数组中的所有元素,并在数组中的每个数字后面加上间隔单元格。