【发布时间】:2016-04-21 12:02:20
【问题描述】:
在我的应用程序中,我想在表格视图底部修复一个按钮。
这是我的初始屏幕,
在页脚部分创建的按钮
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(tableView == educateTbl)
{
float footerWidth = 150.0f;
float padding = 10.0f;
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, footerWidth, 50.0)];
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *addEdu = [[UIButton alloc]initWithFrame:CGRectMake(padding, 0, footerWidth - 2.0f * padding, 44.0f)];
addEdu.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
addEdu.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[addEdu setTitle:@"Add Education" forState:UIControlStateNormal];
[addEdu addTarget:self action:@selector(addEducation:) forControlEvents:UIControlEventTouchUpInside];
[addEdu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
addEdu.frame=CGRectMake(0, 0, 200, 30);
[footerView addSubview:addEdu];
return footerView;
}
return nil;
}
后来我就这样了,
我该如何解决这个问题?
【问题讨论】:
-
在按钮中添加约束
-
我建议创建一个视图并将其设置为
tableView.tableFooterView。 -
以上代码将为特定部分设置页脚视图。尝试像这样将视图设置为 tableFooterView,self.tableView.tableFooterView = addEdu;
-
你也实现了
-tableView:heightForFooterInSection:吗? -
为页脚视图设置不同的背景颜色。这样您就可以了解框架大小及其放置位置
标签: ios objective-c uitableview uibutton tablefooterview