0

我正在使用目标 C 中的 X-Code 开发 iPhone 应用程序。我想在表格底部添加一个蓝色页脚(与页眉相同)。

任何人都可以帮助我建议如何实现这一点。另外如何在此页脚中添加按钮。

提前致谢。

在此处输入图像描述

4

5 回答 5

2

希望对你有帮助

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    [viewFotter setBackgroundColor:[UIColor blueColor]];
    return viewFotter;
}

但问题是,你不能调整按钮的大小。因为它对我不起作用。

于 2012-11-29T06:27:29.920 回答
1

将此代码粘贴到您的.m文件中,您也可以在页脚视图中添加图像

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

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    [viewFotter setBackgroundColor:[UIColor blueColor]];
    UIButton *GoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [GoBtn setTitle:@"GO" forState:UIControlStateNormal];
    GoBtn.frame = CGRectMake(85, 7, 150, 39 );
    [GoBtn addTarget:self action:@selector(GOButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [viewFotter addSubview:GoBtn];
    return viewFotter;
}
于 2012-11-29T04:52:28.823 回答
1
 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 40;
  }

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
            UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
            footerView.backgroundColor =[UIColor blueColor];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setTitle:@"BUTTON" forState:UIControlStateNormal];
            btn.frame = CGRectMake(100, 5, 100, 30 );
            [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            [footerView addSubview:btn];
            return footerView;
    }

   -(void) btnClicked:(id) sender{
     //ur code
    }
于 2012-11-29T04:58:16.147 回答
0

您可以使用所需的组件( 、 等)创建自定义视图,UIButtonUIImageView-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

或者您可以将相同的视图分配给 tableFooterView

tableView.tableFooterView = yourBlueView;

于 2012-11-29T04:50:02.417 回答
0

您可以通过将按钮拖动UIButton到 xib 的页脚来添加按钮UITableView。但是您不能调整按钮的大小,因为它会自动分配给表格视图的宽度。但我不明白你在说什么关于页脚颜色。你能详细说明一下吗?

于 2012-11-29T05:00:47.077 回答