2017-06-15 140 views
0

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

注意:在屏幕下方可以看到屏幕底部增加了一个页脚(白色视图)。 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; 
} 
+0

节的页脚将不会出现在表视图部分的底部,除非你的部分具有足够的细胞覆盖屏幕。 – dip

+0

检查以下链接可能对您有用https://stackoverflow.com/a/7238601/5184217 –

回答

1

试试这个,而不是返回您的自定义视图在viewForFooterInSection

添加您的自定义视图表页脚viewDidLoad中()

self.tableview.tableFooterView =//Your CustomView; 
+0

谢谢,它工作正常 –

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];