在表格视图的底部添加一个按钮

pix*_*eak 2 iphone objective-c ios

有没有更好的方法在表格视图的底部添加按钮,如下所示?我发现的解决方案涉及在现有部分的页眉或页脚中插入一个按钮,对我来说似乎有些苛刻.

在此输入图像描述

The*_*der 7

创建一个新的UIView并将视图设置为tableview的页脚视图,并将该按钮添加为新UIView的子视图.另外,在heightForFooterInSection方法中设置页脚的高度.

在viewDidLoad中有这样的东西,

- (void)viewDidLoad
{
    UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(10, 70, 300, 45)];
    submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [submit setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //[submit setTitleColor:[UIColor colorWithWhite:0.0 alpha:0.56] forState:UIControlStateDisabled];
    [submit setTitle:@"Login" forState:UIControlStateNormal];
    [submit.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
    [submit setFrame:CGRectMake(10.0, 15.0, 280.0, 44.0)];
    [newView addSubview:submit];

    [self.tableView setTableFooterView:newView];

    [super viewDidLoad];

}

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

    return 50;
}
Run Code Online (Sandbox Code Playgroud)