2012-04-07 82 views
0

于是下,我已经实现了这个方法页脚添加到我的表视图:将在UITableView的页脚中的按钮,使的UITableViewCell不页脚

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

这是结果:

enter image description here

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

1)我想补充表视图页脚中的按钮,但是当我将一个按钮控制在故事板,它不起作用。如何在那里添加一个按钮?

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

我使用Xcode 4.2和Snow Leopard。

回答

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

是委托方法。尝试改为访问您的表的sectionFooterHeight属性。

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

+0

我做到了。我用sectionFooterHeight,现在页脚完全不出现。 – 2012-04-07 11:36:05

1

可以使用的tableView:viewForFooterInSection:方法添加按钮,页脚tableviews底部的

1

增加contente大小

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

什么是self.myToolbar? – 2012-04-07 14:22:59

+0

可以是任何高度,只是一些代码的副本,请参阅编辑 – FoJjen 2012-04-07 14:26:00

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