I have couple of problems with my UITableView
.
When I add a UITableview
on my page, by default it brings up some fixed number of rows,
I solved the problem by creating a simple UIView as footer view with the same background color as the table background:
(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)] autorelease];
view.backgroundColor = [UIColor whiteColor];
return view;
}
Maybe you have to disable scrolling in your table view in addition.
- (void) viewDidLoad
{
[super viewDidLoad];
self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];
}
NEW ANSWER
In Swift 2.2, 3.0 and onwards, do the following:
tableView.tableFooterView = UIView()
OLD ANSWER BELOW. KEPT FOR POSTERITY.
If you must use UITableViewStylePlain
, and you don't use a footerView for anything else, you can use the following semi-dirty solution if you have ARC enabled.:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] init];
return view;
}
If you have ARC disabled, use the following:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[[UIView alloc] init] autorelease];
return view;
}
This creates an invisible footerView, that appears immediately after the last data-filled cell.
If your tableview has multiple sections, you may try using this:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == tableView.numberOfSections - 1) {
return [UIView new];
}
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == tableView.numberOfSections - 1) {
return 1;
}
return 0;
}
For Swift:
override func viewWillAppear(animated: Bool) {
self.tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
// OR
self.tableView.tableFooterView = UIView()
}
For C#: (Please don't forget to add using CoreGraphics;
)
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.sampleTableview.TableFooterView = new UIView(frame: CGRect.Empty);
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
and for iOS 7
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];