TableView Header like iOS 7 Mail and Messages App - ios

EDIT: I think I am narrowing down the issue here. I just found an easier way to recreate what I want. If you create a new project with a storyboard, drag on a tableview controller and drag on a Search Bar as a subview of the tableview. If you run this (with some dummy cells), and you scroll so about half of the search bar is showing, the search bar will snap to the top of the view. If you try this by dragging on a UIView instead of a Search Bar, this behavior no longer happens. How can I get this behavior with a UIView as a subview?
Hopefully this made it more clear, thanks guys.
I have a header in my plain style table view, I am implementing it like this:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 51;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
SegmentedHeaderView *header = [[SegmentedHeaderView alloc]initWithFrame:CGRectMake(0, 0, 320, 51)];
return header;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 51;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
I want the header to scroll with the tableview and not stick to the top, and it does that correctly. However, when I scroll to the top, I want the header to work like the search bar header does in the messages app in iOS 7. In the messages app, when you are scrolling and you stop halfway through the search bar, either the search bar sticks to the top of the view, or the first cell sticks to the top of the view.
How can I implement this so when the user stops scrolling with part of the header view showing the header jumps up?
Edit: The behavior I want can also be seen with the search bar in the Mail app.

Related

Where should I add my subview to have it UNDER my table view in a UITableViewController?

I'm using parse's PFQueryTableViewController, which is almost exactly the same as a UITableViewController except it handles some querying in the background.
My goal is to place a static toolbar at the bottom of the screen. I decided to do this by giving tableView a smaller frame, and creating and adding my toolbar subview below the tableView, as a subview to the same view that the tableView is a subview of.
Here's a photo. I am trying to add my toolbar to the little white space at the bottom of the screen. That whitespace does NOT scroll with the table view:
I have tried [self.view addSubview: toolbar], however, this just adds it to the tableView, and as a result, my toolbar scrolls with it. I can't seem to find any documentation on the view hierarchy for a UITableViewController. Anyone know where I should add my toolbar subview? I should also mention that all of this is sitting inside of a UINavigationController.
A PFQueryTableViewController (like all UITableViewControllers) has a table view as its view.
If you want to have other views within the view controller, either don't use a table view controller, or subclass UINavigationController.
Alternatively, you can set the view controller's toolbarItems property, and the navigation controller will take care of making and configuring a standard toolbar.
implement viewFAorHeaderInSection delegate method of UITableView:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 90)];
customView.backgroundColor = [UIColor blackColor];
return customView;
}
and heightForFooterInSection
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 80;
}
it should solove your problem.

AppStore style scroll effect

[Update] Ive added some content inset to my table view. So is it possible to add a view in the gap that is created ?
What I want to achieve is the following scroll effect :
Open the AppStore on the iPhone and go to the Featured tab.
Swipe down : Only the table view scrolls down, the banner with images stays fixed
Swipe up : Everything including the banner view moves up.
My initial thoughts were that there is a table view inside a scroll view but Apple advises against doing that ...
My second attempt was to use a table header view, but the header view would scroll both ways.
So what kind of tweaking has to be done to UITableViewController to achieve this effect ?
What I have so far :
What I need is basically this
For example :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y < 0 ){
CGRect frame = self.myView.frame;
frame.origin.y = scrollView.contentOffset.y ;
self.myView.frame = frame;
}
}
It's the idea !
They used sections nothing fancy.
You'll want to use:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Try returning a UIView for the viewForHeaderInSection and it will give you the same as the App Store Features tab.

iOS: UITableView reloadData not showing last cell (on Device)

I have a UITableView showing chat messages. At the bottom of the UIViewController there is a subView containing a UITextField that the user can write his comment and a "post" UIButton. User taps textfield, the keyboard appears pushing up self.view, write his comment then taps post and tableView is reloaded. The new message appears nice after i scroll the tableView at the bottom. The problem is that in simulator it works fine but in the device the last cell is not fully shown.
Any ideas?Thanks!
tableView.contentInset = UIEdgeInsetsMake(0, 0, 10, 0); //values passed are - top, left, bottom, right
set bottom offset as per your needs.
try:
- (void)viewDidLoad
{
[super viewDidLoad];
....
tableView.contentInset = UIEdgeInsetsMake(0, 0, bottomValue, 0);
}
where bottomValue height your textField

Resize UITableview of UISearchDisplayController

I'm using two searchbar on top of eachother in my layout like so :
Both search bar have a UISearchDisplayController that display a suggestions table.
My problem is, the top search bar's display controller draws its UITable over the bottom searchbar like so :
I tried to move the bottom table down in the uisearchdisplaydelegate like so:
- (void)searchDisplayController:(UISearchDisplayController *)controller
didLoadSearchResultsTableView:(UITableView *)tableView
{
float yOffset = 50.0f;
tableView.frame = CGRectMake(tableView.frame.origin.x,tableView.frame.origin.y + yOffset,tableView.frame.size.width, tableView.frame.size.height);
}
But even though the method get called at the right time, it doesnt seem to do anything.
Id basically like the top searchbar suggestion table to be located at the same position as the bottom search bar suggestion table
I'm using storyboards and autolayout latest xcode
In iOS 7, you can just set the y origin to the yOffset. If you print out the frame of the table view in
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView
you'll notice that the origin.y is at 0,0. In iOS 6 however, it's different. If you're planning on supporting both versions you'll need a check in there. Try setting the origin.y in the delegate method mentioned above.

How to make UITable header stick to the top of the screen when using Storyboards?

I've made header using this post: Table Header Views in StoryBoards
But i am unable to make header stick (fix) to the top of the screen while scrolling.
How can that be achieved?
P.S. Table style is plain, and when i tired to overload viewForHeaderInSection and returned outlet for header view, it just got worse.
Thanks in advance!
Here's the code which I believe makes the header view stick to the table top (that is not it's default behavior):
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect rect = self.tableHeaderView.frame;
rect.origin.y = MIN(0, self.tableView.contentOffset.y);
self.tableHeaderView.frame = rect;
}
An alternative is to have header view for the first section. You can't use any subview at viewForHeaderInSection, you have to return there the view which is not yet at views hierarchy. The advantage of the method is that the section header view is designed to be at the table top, the drawback is that you might want to have headers for sections in the feature, it will break the solution.
I think it's better for you to use a UIViewController, instead of a UITableViewController in the storyboard, to achieve this. Just put a header in the top of the view, in the storyboard, and put a UITableView under the header.
I was able to do it (at least in iOS 6) like this, don't know why this thing works:)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if(self.headerManualView == nil) {
//allocate the view if it doesn't exist yet
headerManualView = [[UIView alloc] init];
//create the button
UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(10, 3, 250, 44)];
//the button should be as big as a table view cell
txtField.borderStyle = UITextBorderStyleRoundedRect;
//set action of the button
//[txtField addTarget:self action:#selector(removeAction:) forControlEvents:UIControlEventTouchUpInside];
//add the button to the view
[headerManualView addSubview:txtField];
}
//return the view for the footer
return headerManualView;
}

Resources