我在viewDidLoad方法中设置页脚视图:
UIView *fView = [[UIView alloc] initWithFrame:CGRectMake(0, 718, 239, 50)];
fView.backgroundColor =[UIColor yellowColor];
self.table.tableFooterView = fView;
Run Code Online (Sandbox Code Playgroud)
不幸的是,页脚没有在(x,y)上面指定的指定中绘制,但是它坚持使用单元格,因此如果表格视图有4个单元格,则页脚将在第5个单元格中绘制.
我甚至尝试过协议方法, tableView:viewForFooterInSection
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *fView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 239, 50)];
fView.backgroundColor =[UIColor yellowColor];
return fView;
}
Run Code Online (Sandbox Code Playgroud)
问题没有解决,我确定tableFooterView属性应该在表视图底部的页脚视图但我不确定我可能在这里缺少什么?Thanx提前.
rma*_*ddy 53
由于您的目标是使页脚保持固定在屏幕底部,而不是使用表格滚动,因此您无法使用表格视图页脚.事实上,你甚至不能使用UITableViewController.
您必须将视图控制器实现为UIViewController.然后,将您自己的表视图添加为子视图.您还可以将页脚添加为视图控制器视图的子视图,而不是表视图.确保您调整表格视图的大小,使其底部位于页脚视图的顶部.
您需要使视图控制器符合UITableViewDataSource和UITableViewDelegate协议,并将所有内容挂钩以复制其功能UITableViewController.
Mar*_*ich 34
页脚视图将始终添加到内容的底部.
这意味着将在节的单元格下方添加节页脚,在所有节的底部添加表格页脚视图 - 无论您在视图中设置的位置如何.
如果你想添加一个"静态"内容,你应该考虑在表视图(superview)之外添加一个视图 - 如果你使用它是不可能的UITableViewController- 或者你使用[self.table addSubView:view]并调整位置/变换到表视图的contentOffset属性该scrollViewDidScroll:委托方法(UITableView是的子类UIScrollView,所以你还可以得到它的委托电话)像这样的代码:
@implementation YourTableViewController {
__weak UIView *_staticView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *staticView = [[UIView alloc] initWithFrame:CGRectMake(0, self.tableView.bounds.size.height-50, self.tableView.bounds.size.width, 50)];
staticView.backgroundColor = [UIColor redColor];
[self.tableView addSubview:staticView];
_staticView = staticView;
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
_staticView.transform = CGAffineTransformMakeTranslation(0, scrollView.contentOffset.y);
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// this is needed to prevent cells from being displayed above our static view
[self.tableView bringSubviewToFront:_staticView];
}
...
Run Code Online (Sandbox Code Playgroud)
coh*_*n72 14
另一种方法是UITableViewController在故事板中使用,并将其作为容器视图嵌入UIViewController中.然后,您可以使用自动布局设置页脚和包含该页脚的容器视图之间的关系UITableView
如果您的表视图或表视图控制器由导航控制器包装,请考虑使用导航控制器的UIToolbar.它总是坚持到底.
[self.navigationController setToolbarHidden:NO];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47889 次 |
| 最近记录: |