【发布时间】:2018-12-24 09:15:04
【问题描述】:
我已经在 IOS 中实现了一个表格视图(4 个部分)。问题是 我刚刚在第一部分添加了一个部分标题。其他部分没有标题。第一部分没有行(行数为 0)。其他部分有多行。当我滚动时,第一部分的标题不粘.它正在滚动并超出屏幕。我的表格视图样式很简单。我怎样才能让第一部分的标题始终保持粘性。代码在下面。不幸的是,表格视图太复杂了,我不想让它只有一个部分所以我已经实现了多部分。
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
}
}
}
【问题讨论】:
-
我编辑了。第一节 ehder 必须是粘性的。
-
getSectionCount()方法的代码在哪里?
-
对不起,我忘记了。关于节数没有问题,但我已将代码更改为仅一个节,并且我管理了一节中的所有单元格。它已完成。感谢您的回答。跨度>
标签: ios uitableview uitableviewsectionheader