viewForFooterInSection未显示在屏幕底部

时间:2017-06-15 10:57:55

标签: ios objective-c

viewForFooterInSection未显示在屏幕底部(uitableview)。 我在这里使用UItableview。image

注意:在屏幕下方的屏幕底部增加了一个页脚。(白色视图)。 Redcolorview:页脚(来自下面的代码) 蓝色:表背景颜色 白底:

红色视图我使用以下代码以编程方式添加:

- (CGFloat)tableView:(UITableView *)tableView 
estimatedHeightForFooterInSection:(NSInteger)section
{
    return 44;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    NSLog(@"%f",tableView.frame.size.width);

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 44)];
    view.backgroundColor = [UIColor redColor];
    UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 7, tableView.frame.size.width/2 - 60, 30)];
    [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
    [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelButton setBackgroundColor:[ValidationsClass colorWithHexString:NSLocalizedStringFromTableInBundle(@"pothysapp_label_text_backgroundcolor",@"ApplicationSettings",[NSBundle mainBundle], nil)]];
    [cancelButton addTarget:self
                     action:@selector(cancelDetails:)
           forControlEvents:UIControlEventTouchUpInside];
    cancelButton.titleLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:15];
    cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [view addSubview:cancelButton];

    UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(tableView.frame.size.width/2 + 30, 7, tableView.frame.size.width/2 - 60, 30)];
    [saveButton setTitle:@"Save" forState:UIControlStateNormal];
    [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveButton setBackgroundColor:[ValidationsClass colorWithHexString:NSLocalizedStringFromTableInBundle(@"pothysapp_label_text_backgroundcolor",@"ApplicationSettings",[NSBundle mainBundle], nil)]];
    [saveButton addTarget:self
                   action:@selector(saveDetails:)
         forControlEvents:UIControlEventTouchUpInside];
    saveButton.titleLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:15];
    saveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [view addSubview:saveButton];

    return view;
}

2 个答案:

答案 0 :(得分:1)

尝试此操作,而不是在 viewForFooterInSection 中返回自定义视图。

ViewdidLoad ()

中将自定义视图添加到表格页脚
self.tableview.tableFooterView =//Your CustomView;

答案 1 :(得分:0)

我删除了estimatedHeightForFooterInSection和viewForFooterInSection。

而不是这个我在viewdidload中添加了视图: self.tableview.contentInset = UIEdgeInsetsMake(0, 0, -20, 0);

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 15, self.view.frame.size.width, 30)];
view.backgroundColor = [UIColor whiteColor];
self.tableview.tableFooterView = view;

UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 7, self.view.frame.size.width/2 - 60, 30)];
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[view addSubview:cancelButton];

UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2 + 30, 7, self.view.frame.size.width/2 - 60, 30)];
[saveButton setTitle:@"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[view addSubview:saveButton];