gpt4 book ai didi

ios - tableview section header 在 multi sectional tableview 中不粘

转载 作者:行者123 更新时间:2023-11-28 19:26:35 29 4
gpt4 key购买 nike

我在 IOS 中实现了一个 TableView (4 个部分)。问题是我刚刚在第一部分添加了一个部分标题。其他部分没有标题。第一部分没有行(行数为 0)。其他部分有多行。当我滚动时,第一部分的标题不粘.it is scrolling and out of screen.My table view style is plain.How can I want to make first section's header is always sticky.代码在下面。不幸的是tableview太复杂了,我不想让它只有一个部分所以我已经实现了它的多部分。

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
return tabHeaderView.contentView
}
else {
return UIView()
}
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
return UITableView.automaticDimension
}
else {
return 0 //just first section have a header (tabview)
}
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}

func numberOfSections(in tableView: UITableView) -> Int {
if dataReady {
totalSectionCount = getSectionCount()
return totalSectionCount
}
else {
return 1 //permanent because of tabview
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
if !dataReady || ApplicationContext.instance.userAuthenticationStatus.value == .semiSecure{
return 1//for shimmer cell and semisecure view
}
else {
return getNumberOfRows(sectionNumber: section)
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if ApplicationContext.instance.userAuthenticationStatus.value == .semiSecure {
semisecureViewCell = EarningsSemisecureViewCell()
setSemisecureViewTextInfo(cell: semisecureViewCell)
semisecureViewCell.delegate = self
semisecureViewCell.layoutIfNeeded()
return semisecureViewCell
}
else if !dataReady {
return getShimmerCell()
}
else {
if indexPath.row == 0 && !(selectedTabIndex == .BRANDPOINT && indexPath.section == 1){//marka puan listesinde header cell olmayacak
return getSectionHeaderViewCell(tableView: tableView,sectionNumber: indexPath.section)
}
else {
let cell = getTableViewCell(tableView: tableView, indexPath: indexPath)
cell.layoutIfNeeded()
return cell
}
}
}

最佳答案

每个部分标题都将固定在顶部,直到该部分有一些行要显示。向上滚动该部分的所有行后。节标题将被下一个节标题替换。

此处您可以使用两种解决方案中的一种。

  1. 而不是 TableView 部分标题。将您的 View 置于 UITableView 之上。
  2. 您可以只使用一个部分并合并其中的所有行。

关于ios - tableview section header 在 multi sectional tableview 中不粘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53911406/

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