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

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

在此处输入图像描述

您正在查看的视图是UITableView。 如果您有多个条目,则此人的信息将与“删除”按钮一起滚动屏幕。 将按钮放在表格页脚中将允许它与表格一起滚动。 表格页脚位于任何部分之外。

如果您的视图没有任何滚动或动态大小的表视图,您只需将其添加到视图的底部即可。

创建一个新的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; } 

如何使用带删除按钮的工具栏? 恕我直言,它会看起来“更好”。

你可以添加一个UIView然后添加一个UIButton ,以便UIButton无法自动调整以适应宽度。