如何向 UITableView 添加页脚?
我使用此代码向 TableView 添加页脚。它有 20 个部分,每个部分有几行。有 titleForHeaderInSection 和sectionForSectionIndexTitle 方法。
CGRect footerRect = CGRectMake(0, 0, 320, 40);
UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
tableFooter.textColor = [UIColor blueColor];
tableFooter.backgroundColor = [self.theTable backgroundColor];
tableFooter.opaque = YES;
tableFooter.font = [UIFont boldSystemFontOfSize:15];
tableFooter.text = @"test";
self.theTable.tableFooterView = tableFooter;
[tableFooter release];
我做错了什么?
谢谢,
RL
I'me using this code to add a footer to the TableView. It has 20 sections, and each section a few rows. There's a titleForHeaderInSection, and sectionForSectionIndexTitle methods.
CGRect footerRect = CGRectMake(0, 0, 320, 40);
UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
tableFooter.textColor = [UIColor blueColor];
tableFooter.backgroundColor = [self.theTable backgroundColor];
tableFooter.opaque = YES;
tableFooter.font = [UIFont boldSystemFontOfSize:15];
tableFooter.text = @"test";
self.theTable.tableFooterView = tableFooter;
[tableFooter release];
What am I doing wrong?
thanks,
RL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我特别在我的代码中看到了
有效和
无效的情况。因此,坚持前者并在其他地方寻找可能的错误。
华泰
I'm specifically seeing in my code that
works and
does not work. So stick to the former and look elsewhere for the possible bug.
HTH
您需要实现 UITableViewDelegate 方法
并返回表格相应部分所需的视图(例如,在页脚中包含您想要的文本的 UILabel)。
You need to implement the UITableViewDelegate method
and return the desired view (e.g. a UILabel with the text you'd like in the footer) for the appropriate section of the table.
我用过它,效果非常好:)
I used that and it worked Perfectly :)
我知道这是一个很老的问题,但我刚刚遇到了同样的问题。我不知道确切的原因,但似乎 tableFooterView 只能是 UIView 的一个实例(不是“某种”,而是“是成员”)...所以在我的例子中,我创建了新的 UIView 对象(例如wrapperView)并向其中添加我的自定义子视图...在您的情况下,将您的代码从:
更改为:
希望它有帮助。这对我有用。
I know that this is a pretty old question but I've just met same issue. I don't know exactly why but it seems that tableFooterView can be only an instance of UIView (not "kind of" but "is member")... So in my case I've created new UIView object (for example wrapperView) and add my custom subview to it... In your case, chamge your code from:
to:
Hope it helps. It works for me.
最初我只是尝试该方法:
但在使用此方法后:
问题得到解决。示例程序 -
并包含 UITableViewDelegate 协议。
Initially I was just trying the method:
but after using this along with:
problem was solved. Sample Program-
and include UITableViewDelegate protocol.
这些样本效果很好。您可以检查部分,然后返回高度以显示或隐藏部分。不要忘记从
UITableViewDelegate
扩展您的视图控制器。Objective-C
Swift
These samples work well. You can check section and then return a height to show or hide section. Don't forget to extend your viewcontroller from
UITableViewDelegate
.Objective-C
Swift
下面的 Swift 2.1.1 有效:
如果使用
self.theTable.tableFooterView = tableFooter
,最后一行和tableFooterView
之间有一个空格。Swift 2.1.1 below works:
If use
self.theTable.tableFooterView = tableFooter
there is a space between last row andtableFooterView
.而不是
尝试
instead of
try
我遇到了同样的问题,但我用此行替换了标题中的以下行:
它按预期工作:
注意 UIViewController。
祝你好运 :)
I had the same problem but I replaced the following line in my header:
with this line and it works as expected:
Notice the UIViewController.
Good luck :)
如果您不喜欢粘性底部效果,我会将其放入
viewDidLoad()
https://stackoverflow.com/a/38176479/4127670
If you don't prefer the sticky bottom effect i would put it in
viewDidLoad()
https://stackoverflow.com/a/38176479/4127670