Swift中的表格视图页脚 [英] Table View Footer in Swift

查看:67
本文介绍了Swift中的表格视图页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Swift在表格视图中创建页脚.始终位于屏幕底部的单个页脚.我设置了一个名为TableViewFooter.swift的.swift文件,该文件创建了一个名为TableViewFooter的类,该类是UITableViewHeaderFooterView的子类. TableViewFooter具有2个标签,一个按钮和一个进度视图.在我的TableViewController中,我输入了代码:

I'm trying to create a footer in a table view using 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 has 2 labels, a button, and a progress view. In my TableViewController I put the code:

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
}

在tableView.registerNib行之后,出现预期的声明"错误,在let currSection行之后,出现使用未解决的标识符'fetchedResultsController'"错误,在发生之后,出现了使用未解决的标识符'header'"错误header.titleLabel.text行.我是新手,但是我使用的是Swift文件,而不是笔尖,所以我不应该放其他东西吗?我发现的唯一教程是使用笔尖或神秘的Apple参考.任何帮助将不胜感激!

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. I'm new at this, but I'm using a Swift file, not a nib, so shouldn't I be putting something else instead? The only tutorials I found are using nibs or the cryptic Apple reference. Any help would be greatly appreciated!

推荐答案

听起来您想要两件事之一:

It sounds like you want one of two things:

UITableView页脚.这是UIScrollView底部的视图,这意味着它仅在您滚动到表格的底部时显示.您可以通过在视图控制器中访问UITableView的tableViewFooter属性来修改此属性,我认为这是您的委托和dataSource.

A UITableView footer. This is a view at the bottom of your UIScrollView, meaning that it only shows when you scroll to the bottom of the table. You can modify this, by accessing the tableViewFooter property of your UITableView, in your view controller, which I assume is your delegate and dataSource.

或者,视图始终保留在屏幕底部.这不是表视图页脚,而是将添加到视图控制器主视图中的视图.为此,请在视图底部添加一个自定义UIView,确保它不与表格视图重叠(否则,用户将无法进入底部单元格),并确保scrollView表格视图的属性"足够大,可以容纳其所有单元格.

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.

这篇关于Swift中的表格视图页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆