Reputation: 330
I need a free Area at the Top (above) of my grouped-style TableView in an UITableViewController. What's the Top? The Area between NavigationBar and SectionTitle of the TableView.
First, i used
UIEdgeInsets inset = UIEdgeInsetsMake(60, 0, 0, 0);
self.tableView.contentInset = inset;
That works fine in the first Moment, exactly what I need. But, if I scroll down the TableView, the view will move into the new free Area.
To work with
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
seems doesn't work :(
Any suggestion?
Upvotes: 3
Views: 1659
Reputation: 902
If your table is read only, jrturton suffices. Otherwise, you also need to propagate the editing call from the UIViewController to the enclosed UITableView as follows:
//In UIViewControler propagate call to tableView property
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
Upvotes: 2
Reputation: 119242
The root view of a table view controller is the table view, so you can't put things above or below it, as there isn't a superview for you to add them to.
The solution is to use a UIViewController subclass instead, to this you can add a table view of any size, with views above and below it. There isn't much additional work involved - you have to declare that your view controller implements the delegate and datasource protocols, and connect those outlets up in IB, aside from that it's the same as a table view controller.
Basic message - you can have a table view without a UITableViewController.
Upvotes: 4
Reputation: 1541
So you need a space above the Table view, which doesn't get covered by the table view when it is scrolled?
Instead of playing around with the table view, just try to add a UILabel
on top of the table view or in place where the header of table view would have been there. Then make the table view's co-ordinates start right below that of the label. This way when you scroll, the space, i.e; the label here, is always visible.
The reason to do this is because everything defined for a UITableView
, such as the header or footer, is always associated with the table, and cannot be manipulated separately.
Upvotes: 0
Reputation: 5267
You can use the headerView property of table create one view with required size and put it in the header view of table it will give you what you exactly need.
You can use -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
delegate method of tableView to put the header view for first section.
Happy Coding :)
Upvotes: 0