在UITableView页脚中放置一个按钮,使UITableViewCell不在页脚下

时间:2012-04-07 10:47:07

标签: iphone objective-c ios xcode

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

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

结果如下:

enter image description here

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

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

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

我正在使用Xcode 4.2和Snow Leopard。

4 个答案:

答案 0 :(得分:2)

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

是委托方法。请尝试访问表格的sectionFooterHeight属性。

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

答案 1 :(得分:2)

使用此功能为表格

创建页脚视图
- (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;
}

在viewDidLoad方法中使用此函数

yourTableObjectName.tableFooterView = [self createViewForTableFooter];

答案 2 :(得分:1)

你可以使用tableView:viewForFooterInSection:方法向页脚添加按钮

答案 3 :(得分:1)

增加表格视图底部的内容大小

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