Setting UITableView contentInset also insets section header view - iphone

I'm changing my tableviews contentInset, so that when a user scrolls beyond the top bounds of the table, the tableview is inset to display a UISearchBar hidden above the tableView.
Everything works fine apart from the section header views. when scrolling down, the top bound of the sectionHeaderView is inset the same distance from the top of the screen as my tableview inset, here is it in starting position:
In the above image the sectionheader view is set to its correct positon, and the tableview inset has been set to display the search field.
You can see in this second screenshot where the top bound of the headerview is set lower because of the 43 pixel tableview inset, where as it should stick to the top of the screen hiding the "related" cell and bouncing back when released.
I guess i need to Offset the Inset somehow, i'm just not sure how..

I am assuming what you want is a search field like in the Mail application; a search field at the very top of the list that by default is not visible?
The solution is not to use contentInset, but instead:
Set a UISearchBar as the tableviews tableHeaderView.
Also add a UISearchDisplayController to the table view controller.
By default set the contentOffset to 44 points down, to hide the search bar.
Apple has a good sample app as a starting point here: http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

Related

Gap above ContentView / not the same height as UIScrollview - xib

Issue: gap above where contentView starts. Should be 0.
Despite setting the content view top bottom leading and trailing to 0, the content view has a gap at the top. I am using auto layout only.
Scrollview background is blue &
Content view is grey for easy viewing.
If I set the content view to equal heights as the scroll view, I get an error. And this doesn't seem like the right approach away. According to this setting equal height is optional:
Apple auto layout scrollview page
I do set equal widths.
Entire Screen:
Top of Scroll view:
Bottom of scroll view -> this is right - flush with bottom of scroll view (not sure if that matters)
Constraints:
Subview constraints:
Please help!! Also I am using xib files - not sure if that matters.
Thank you!
You'll notice that the gap is equal in height to the navigation bar.
The gap is there because by default iOS assumes that when using a translucent navigation bar, scroll views (and their subclasses like table views) begin at the top of the screen, behind the translucent navigation bar.
iOS then assumes you do not want your content hidden behind the translucent navigation bar, so it applies a top content inset to any scroll view, of height equal to the navigation bar height.
This behavior can be overridden in two ways:
Unmark Adjust Scroll View Insets on the view controller (see image below)
Make your navigation bar not translucent. If you're using a Storyboard, select the navigation controller that contains the affected view controller, and unmark the Translucent checkbox.

How to move a subview to front and have existing view shift up to make room?

I have a collectionview that takes up the whole screen. Once the user clicks a cell and does stuff in the detail view, they are sent back to the first collectionview screen. At this point, I am bringing a view to the front that is a pseudo-tabbar. I want to shift the collection view up to accommodate this new view. Right now, it is just blocking the bottom row of collectionview cells. Thanks in advance!
Put the pseudo-tab bar in the initial view and constrain your collection view's bottom to the top of the tab bar.
Set the tab bar's initial height to 0. Don't just set it to hidden, because that keeps the view's original height.
When the user returns to the collection view, set the tab bar's height to the desired value. Animating it in will look even better.

Extending a vertical UIScrollView with pagingEnabled under the navigation and status bars

I'm trying to extend a vertical UIScrollView with pagingEnabled underneath the navigation and status bars.
For other, non-paging scroll views, increasing the frame upwards and adjusting contentInset works fine. However, doing this with a paging scroll view affects the amount paged each swipe – effectively breaking paging as the pages don't line up to the height paged.
Trying to use this sort of solution, i.e. maintaining the frame the same size and setting clipsToBounds = NO, kindof works. However, it only displays the above cell if it's actually visible within the frame – the 66 pixels underneath the status and navigation bars don't count.
How can I do this?
On your view controller you will need to set
self.automaticallyAdjustsScrollViewInsets = NO;
This should effectively stop adding the extra spacing above the view.

iPhone how to implement a "Wide" UITableViewCell?

I'd like to have a UITableView with cells wider than 320 points. The user should be able to scroll sideways to be able to view different parts of a UITableViewCell. Is this kind of behavior possible with a UITableView, or should I go and try to implement a tiling UIScrollView?
I tried wrapping a UITableView within a UIScrollView, and the results are terrible - they compete for the scroll gestures and most of the time the scroll view wins, preventing the table from being traversed vertically.
Any input is appreciated!
Thank you!
Update: I tried the proposed solution and it scrolls properly, but the tableview is still only 320 pixels wide. Is tableView's width linked to the window bounds ?
Wrapping the table view with the scroll view is the right way.
UIScrollView with
Show horizontal scrollers
scrolling enabled
autosize to full screen
Inside that, a UITableView
shows vertical scrollers
scrolling enabled
Then I set the table view's frame, with w, being the calculated width of the table view with all columns, whatever your width, and kTableScrollViewHeight being the fixed height of both the table view and the scroll view, in my case, for example 367 points (screen minus status, navbar and tabbar):
tv.frame = CGRectMake(0, 0, w, kTableScrollViewHeight);
and the scroll view's content size
scrollView.contentSize = CGSizeMake(w, kTableScrollViewHeight);
If you want the scroll-to-top behavior when the user taps the status bar, you might want to set
scrollView.scrollsToTop = NO;
because otherwise the scroll view will take away the tap from the table view.

Mimic behaviour of UITableView section headers staying visible during scroll

When you have a sectioned, plain-style tableview on the iPhone, such as in the Contacts app, the section headers remain visible when you scroll past them until they are pushed offscreen by the next section header.
Does anyone know how to achieve something like this in an ordinary scrollview? I already have one scrollview nested in another to get horizontal paging with vertical smooth-scrolling, so I'm reluctant to add a third scrollview.
Cheers
Basically I did a bunch of maths in scrollViewDidScroll: and set the frame of the subview.
Edit:
Well my exact requirements were a bit different than the question I asked, I have a footer view as opposed to a header view. Basically in scrollViewDidScroll I have:
CGRect frame = self.footerView.frame;
frame.origin.y = MIN(self.bounds.size.height -
self.footerView.frame.size.height +
self.contentOffset.y,
self.contentSize.height);
self.footerView.frame = frame;
This ensures the footer view, which is a subview of the scroll view, is always visible at the bottom of the scroll view, and there is never a gap between the footer view and the bottom of the content view.