【发布时间】:2021-02-26 17:12:44
【问题描述】:
我有两个自定义 TableViewCell。所以第一个 TableViewCell 就像一个最近的列表,它可以变得更长。但第二个单元格始终停留在底部。所以我需要添加持有 secondTableViewCell 的 UILabel。 the result that i need.
import UIKit
class bagPage: UIViewController, UITableViewDelegate, UITableViewDataSource {
var itemsName: [String] = []
var itemsPhoto: [UIImage] = []
// these arrays will defined in other view controller
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row < itemsName.count{
return 165
}else{
return 50
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6 + itemsName.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row < itemsName.count{
let cell = tableView.dequeueReusableCell(withIdentifier: "bagTableViewCell") as? bagTableViewCell
cell?.itemName.text = itemsName.last
cell?.itemPhoto.image = itemsPhoto.last
return cell!
}
if indexPath.row == itemsName.count {
let cellTwo = tableView.dequeueReusableCell(withIdentifier: "extraBagPageTableView") as? extraBagPageTableView
// here i'm hiding views in first row
cellTwo?.textLabel?.text = "These are products that u can add to your cell"
return cellTwo!
}else{
let cellTwo = tableView.dequeueReusableCell(withIdentifier: "extraBagPageTableView") as? extraBagPageTableView
return cellTwo!
}
}
}
【问题讨论】:
-
我想我的其他解决方案不是您想要的,请允许我再次尝试并提供帮助。我认为我的困惑是您所说的包含第二个 tableview 单元格的标签的方式。你的意思是什么,因为你的图片没有让问题更清楚?试着解释你所说的保持是什么意思。你想让第二个单元格中的标签做某事吗?
-
看,我将两个 UITableViewCells 拖到了我的 tableView 中。第一个可以通过用户的操作变长。但第二个,总是停留在底部,我需要一个 UILabel 来描述第二个单元格的内容。我添加了我的故事板的照片
-
否则它们在第一个单元格中可以是无限行,但第二个单元格中只有五个,并且标签应该像第二个单元格的第一行。我希望你能理解我。
-
我将两个 UITableViewCells 拖到了我的 tableView 中。 OK - 第一个可以通过用户的操作变得更长。好的 - 但第二个,总是留在底部好的 - 我需要一个 UILabel 来描述第二个单元格的内容。不行 你需要解释一下这个标签是什么。图片不解释。
-
否则它们在第一个单元格中可以是无限行 好的,我知道根据用户交互,单元格可以变长 - 第二个单元格您还没有清楚地解释它的不同之处。我真的很想帮助你,但我很难理解第二个单元格中的标签是做什么的
标签: ios swift uitableview uitableviewsectionheader