How to add a custom view to top of tableView in UIViewController and be able to scroll together - ios

I'm trying to put a big UIImageView on top of a UITableView inside my UIViewController. I read that I should not put a UITableView inside a UIScrollView and so I'm trying to find out how to best approach this.
Right now, in my UIViewController what I have is a huge UIImageView (covering half of screen) and below that I have my UITableView.
The problem is that the scroll only works for the UITableViewCell, but I cannot scroll up so that the image goes to the top and invisible...
Thanks for the help!

Make the tableview the height of the view controller's view then in viewDidLoad say something like:
self.imageView.removeFromSuperView()
self.tableView.tableHeaderView = self.imageView
If you're using auto layout you should move the second line to viewsDidLayoutSubviews

Related

Need assistance showing custom UIView when UITableView is dried down

I am trying to achieve whatsapp style drag tableview to show custom view, here is the screenshot
but I am clueless how to show custom UIView on top of UITableView when UITableView is dragged down
You can place your UIView behind the table view, and have its height grow as you drag down. Where you read the scroll offset for your table views scroll delegate.

how to make a space at the bottom of a UITableView in a UITableViewController

I want to add a footer to the UITableView, there are two ways, either footer for the section, or footer for the UITableView. Both don't work for me because I want to footer always at the bottom of the screen. In other words, floating footer.
That's why after searching, people suggest to but the footer under the UITableView. I would need to resize the UITableView and add the footer through IB under it. That makes sense and that's what I am asking for.
Kindly I have a specific problem and It's not about footer at all
My problem is that I couldn't create constrains for the UITableView that locates inside UITableViewContoller, whenever I click Ctrl + drag, I don't see the options that I would normally see.
Is that because I'm working with UITableViewController?
This is a screenshot of my hirechy
Again I would like to resay that my problem is not about footers, my problem is about how to resize the UITableView in a UITableViewController
I created a sample project with a fixed footer. You can download it here. What I have added is:
ContainerView 100%
- TableView 90% of the ContainerView and constraints to the ContainerView
- View 10% of the ContainerView and constraints to the ContainerView
You shouldn't resize the UITableView of an UITableViewController object : your tableview is in fact your main view.
If you want to put a empty space that can't be scrolled below an UITableView, you should use an UIViewController instead.
Add an UITableView and an UIView to this UIViewController object.
Set the left, right, and bottom constraints aligned to its superview for the UIView, and fix its height with a fourth constraint. Add the left, right and top constraints aligned to its superview for the UITableView, and set the vertical space between the view and the tableview to 0 with a constraint.
Yes, you are correct. You cannot add a footer on a UITableViewController. For this I recommend using a UIViewController.
Follow these steps if you want to add a footer:
create UIViewController
Add footer to the bottom and add constraints to the bottom border.
Add UITableView to the UIView, and add constraints to the footer.
Also for the controller, just create two classes within the same file, and make one of them as a UITableViewController and the footer as regular class within the file.
If you just want space you should just use UIViewController. Add UITableView inside that, and put constraints on that.
This is one approach, and there maybe many other. Please let me know if I can help you any further.

How do I add a footer to a UITableView using Storyboard?

Same as this question, only the proposed solution doesn't work for me. When I drag a view to the bottom area of a tableView, it tries to add it to the list of cells higher up:
I'm sure I'm missing something simple... I'm new to storyboards.
EDIT:
Maybe it is adding a "footer" (though, it doesn't label it as such), it's just not adding it low enough. I was ultimately hoping to add an item that would appear at the bottom of the screen (and stick to the bottom of the screen).
TIP: You can use the Tree view (outline view) on the left to arrange the Views (and sub views). I have done a lot of storyboard editing, and dropping things into table views rarely go to the correct hierarchy level in the tree view.
Create a New UIViewController
Insert a UITableView
Resize the tableview by dragging its dimensions
The attached picture has a UITableView on TOP of a UIViewController's UIView. Make sure that you set the delegates in the UIViewController's .m, assign the tableView as a property of the view controller, and then set the tableview's delegate property to the UIViewController object. i.e.: tableView.delegate = self or [tableView setDelegate:self]; also with datasource.
OR you can just click the tableView, on story board, and then drag its delegate and datasource property to THE UIVIEWCONTROLLER! not the view! You can do this by dragging it to the this highlighted part of the view controller's toolbar on the storyboard:
Either you can create a footer view programatically or you can load a view from UIView outlet
UIView *tempFooter=[[UIView alloc]initWithFrame:self.Footerview.frame];
[tempFooter addSubview:self.Footerview];
self.ItemDetailsTable.tableFooterView=tempFooter;
self.Footerview //View outlet
You need to set all the needed constraints of the self.Footerview to get the required layout of the footer view.But you don't need to set constraints for tableview footer itself.

Scrolling up UICollectionView don't move a UIView above it

I am working in a profile ViewController. This profile has a main image in a UIView subclass and a CollectionView gallery with some images. I would like to be able to scroll up the UICollectionView and move the UIView too, and if I scroll down, I want to watch again the UIView when the collectionView first item is showed again.
I have tried to do this adding the collectionView and the UIView to a ScrollView, but the UIView only scroll up if I touch it.
In this picture you can see my problem
Thank you in advance
You need to make the view at the top a Header View of the collection view.
Essentially it needs to be an actual part of the collection view if you want this action. (That's the easiest way anyway).
So the collection view will take up the whole screen but it will have a header view. Then when you scroll the collection view the header will move out of view and then come back in when you scroll down again.

iOS: Stretching ImageView Above My TableView?

I have added a UIImageView on top of my tableView in storyboard & it works perfectly fine, except that when you scroll down, the imageView doesn't stick to the navigationBar and instead only sticks on to the tableView (revealing the view's background above it).
How would I get it to stick to both the tableView and the navigationBar, and just have the imageView stretch/zoom as the user pulls the tableView down?
This is how it's set up in storyboard:
And this is how I assign an image to it in my ViewDidLoad:
childHeaderView.image = [UIImage imageNamed:headerImage];
Any help would be greatly appreciated. I've tried setting constraints on it using autoLayout but it doesn't seem to let me (they're grayed out, even though I've enabled it for that ViewController).
The problem is that what you did in storyboard is adding the UIImageView as a header to your UITableView.
The proper way to do this is to add the UIImageView at the same level as the UITableView, which mean embed these two views inside a UIView.
Having a UIView as a root view for a view controller is unfortunately impossible for a UITableViewController, and I fear that this is your case. So you may want to replace your UITableViewController subclass by a UIViewController subclass.
EDIT: You'll want to set a fixed height constraint on your UIImageView, and add a vertical space constraint with a 0pt value between your UIImageView and UITableView.
Most of these can be achieved by moving view in IB.

Resources