xcode 在 UITableView 页脚中放置一个按钮并使 UITableViewCell 不在页脚下方

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10053802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:53:30  来源:igfitidea点击:

Place a button in UITableView footer and make the UITableViewCell not be under the footer

iphoneobjective-ciosxcode

提问by Richard Knop

So, I have implemented this method to add a footer to my table view:

所以,我已经实现了这个方法来向我的表格视图添加一个页脚:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 60;
}

This is the result:

这是结果:

enter image description here

在此处输入图片说明

Now, you see, there are two problems:

现在,你看,有两个问题:

1) I would like to add a button inside the table view footer but when I drag a button control in the storyboard, it does not work. How to add a button there?

1) 我想在表格视图页脚中添加一个按钮,但是当我在故事板中拖动按钮控件时,它不起作用。如何在那里添加按钮?

2) As you can see, the footer is transparent and there is a table view cell visible under it. I would like there to be no cells under the footer (so the last visible cell would be the one above the footer). Second, I would like the footer not to be transparent.

2)如您所见,页脚是透明的,并且在其下方可见一个表格视图单元格。我希望页脚下没有单元格(因此最后一个可见单元格将是页脚上方的单元格)。其次,我希望页脚不透明。

I am using Xcode 4.2 and Snow Leopard.

我正在使用 Xcode 4.2 和雪豹。

回答by Manlio

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

is a delegate method. Try instead to access sectionFooterHeightproperty of your table.

是一个委托方法。尝试访问表的sectionFooterHeight属性。

To add a button you may consider adding a custom view to your footer. You can access tableFooterViewand assign a custom view to it.

要添加按钮,您可以考虑向页脚添加自定义视图。您可以访问tableFooterView并为其分配自定义视图。

回答by Rahul Vyas

Use this function to create a footer view for table

使用此函数为表格创建页脚视图

- (UIView *) createViewForTableFooter
{
    CGRect footerRect = CGRectMake(0, 0, self.view.frame.size.width, 60);
    UIView *tableFooter = [[[UIView alloc] initWithFrame:footerRect] autorelease];
    tableFooter.backgroundColor = [UIColor clearColor];

    UIButton* verifyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [verifyButton setTitle:WNLocalizedString(@"Verify",@"") forState:UIControlStateNormal];
    [verifyButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
    [verifyButton addTarget:self action:@selector(verifyBtnTapped:)forControlEvents:UIControlEventTouchUpInside];
    verifyButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [verifyButton setFrame:CGRectMake(44, 10, self.view.frame.size.width - 88, 37)];
    }else {
        [verifyButton setFrame:CGRectMake(10, 10, self.view.frame.size.width - 20, 37)];
    }
    [tableFooter addSubview:verifyButton];

    return tableFooter;
}

And use this function like this in your viewDidLoad method

并在您的 viewDidLoad 方法中像这样使用这个函数

yourTableObjectName.tableFooterView = [self createViewForTableFooter];

回答by The iOSDev

you can use tableView:viewForFooterInSection: method to add button to the footer

您可以使用 tableView:viewForFooterInSection: 方法将按钮添加到页脚

回答by FoJjen

increase contente size of tableviews bottom

增加 tableviews 底部的内容大小

UIEdgeInsets contentInset = self.tableView.contentInset;
contentInset.bottom = 50.0f; // **the height of the footer**
self.tableView.contentInset = contentInset;