简体   繁体   English

Swift中的表格视图页脚

[英]Table View Footer in Swift

I'm trying to create a footer in a table view using Swift. 我正在尝试使用Swift在表视图中创建页脚。 A single footer that's always at the bottom of the screen. 始终位于屏幕底部的单个页脚。 I set up a .swift file called TableViewFooter.swift that creates a class called TableViewFooter, a subclass of UITableViewHeaderFooterView. 我设置了一个名为TableViewFooter.swift的.swift文件,该文件创建了一个名为TableViewFooter的类,该类是UITableViewHeaderFooterView的子类。 TableViewFooter has 2 labels, a button, and a progress view. TableViewFooter具有2个标签,一个按钮和一个进度视图。 In my TableViewController I put the code: 在我的TableViewController中,我放入了代码:

let nib = UINib(nibName: "TableViewFooter", bundle: nil)
tableView.registerNib(nib, forHeaderFooterViewReuseIdentifier: "TableViewFooter")

override func tableView(tableView: UITableView, viewForHeaderInSection     section: Int) -> UIView? {
let currSection = fetchedResultsController.sections?[section]
let title = currSection!.name

let cell = self.tableView.dequeueReusableHeaderFooterViewWithIdentifier("TableViewFooter")
let header = cell as! TableViewFooter
header.titleLabel.text = title

return cell
}

I'm getting an "Expected declaration" error after the tableView.registerNib line, a "Use of unresolved identifier 'fetchedResultsController'" error after the let currSection line, and a "Use of unresolved identifier 'header'" error after the header.titleLabel.text line. 在tableView.registerNib行之后,出现“预期的声明”错误,在let currSection行之后,出现“未使用的标识符'fetchedResultsController'使用”错误,在标头之后出现了“未使用的标识符'header'使用”错误。 titleLabel.text行。 I'm new at this, but I'm using a Swift file, not a nib, so shouldn't I be putting something else instead? 我是新手,但我使用的是Swift文件,而不是笔尖,所以我不应该放其他东西吗? The only tutorials I found are using nibs or the cryptic Apple reference. 我发现的唯一教程是使用笔尖或神秘的Apple参考。 Any help would be greatly appreciated! 任何帮助将不胜感激!

It sounds like you want one of two things: 听起来您想要两件事之一:

A UITableView footer. UITableView页脚。 This is a view at the bottom of your UIScrollView, meaning that it only shows when you scroll to the bottom of the table. 这是UIScrollView底部的视图,这意味着它仅在滚动到表格底部时显示。 You can modify this, by accessing the tableViewFooter property of your UITableView, in your view controller, which I assume is your delegate and dataSource. 您可以通过在视图控制器中访问UITableView的tableViewFooter属性来修改此属性,我认为这是您的委托和dataSource。

Or, a view that always remains at the bottom of your screen. 或者,视图始终保留在屏幕底部。 This is not a table view footer, but a view that you will add to the main view of your view controller. 这不是表视图页脚,而是将添加到视图控制器主视图的视图。 To do this, add a custom UIView at the bottom of your view, making sure that it does not overlap with your table view (otherwise, the user won't be able to get to the bottom cell), and make sure that the scrollView property of your table view is large enough to contain all of its cells. 为此,请在视图底部添加一个自定义UIView,确保它不与表格视图重叠(否则,用户将无法到达底部单元格),并确保scrollView表格视图的属性足够大,可以包含其所有单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM