2

在我的应用程序中,我想修复表格视图底部的按钮。

这是我的初始屏幕,

在此处输入图像描述

在页脚部分创建的按钮

-(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;
}

之后我就变成这样了

在此处输入图像描述

我该如何解决?

4

4 回答 4

3

你为什么不做这样的东西?

-(void)setTableFooter
{
   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];

   tableView.tableFooterView = footerView;

}

并在你初始化表后调用它

于 2016-04-21T14:43:02.150 回答
0

如果您希望使用 tableview 滚动部分页脚/页眉,则需要使用分组样式表视图。

[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped]

并且分组样式表视图将具有默认的背景颜色和部分页眉/页脚高度。您需要明确设置这些值。

如果您只有一个部分,最好使用tableFooterView部分页脚视图而不是部分页脚视图

于 2016-04-21T13:01:44.783 回答
0

虽然滚动该按钮可见意味着,UITableview 单元格是可重用的,以便该按钮可用,您必须做的就是。

1.获取 UITableView 中的行数,

然后在 indexpath 处的单元格内:

Total number of row ==indexpath.row
{
   //inside this button.hidden=no;
}
else
{
   //button.hidden=yes;
}
于 2016-04-21T14:21:18.037 回答
0
-(void)CreateCustomFooter
{
   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];

   tableView.tableFooterView = footerView;

}

将上述方法放在 viewDidLoad() 方法中并在初始化 tableview 之后

于 2016-04-21T12:27:09.503 回答