I need a fixed header that does not go from view. I intend to keep summary of tableview below. So I started off with a UIViewController and trying to put UIView and UITableView under that.
In UIView I added a UIButton, UILabel but I'm running into layout constraints.
In UITableView, when I change orientation cell is not filling up the view. why is that? Am a newbie to ios programming. Appreciate any pointers.
Pl see the images below.
Looks like You didn't pinned all your tableview edges with superview thats why this happened..
select tableview and Pinned all edges of tableview with superview thats all..see below image
Related
In my storyboard I have a UITableView and above the dynamic cells I added a UIView to keep there a photo and some labels.
Currently, I want to apply constraints to the photo so that it reaches the top, left and right side of the screen and keeps the aspect ratio. However, the storyboard looks like this:
The constraints for photo are:
However, as you see, the constraints are marked in red and when I run the app the photo is not stretched properly.
What is causing this issue?
I would probably do this programmatically. It is pretty simple to create a custom view and set it as your header view. You can either create a UIView with a UIImageView inside of viewForHeader or by assigning it to the entire table with tableView.tableHeaderView = headerView.
I want to put my UIView inside of UICollectionView(on top) that on scroll it scrolls with UICollectionView content. It's possible to put it on header part in UITableView, I did it, but in UICollectionView I cannot achieve the same effect. How can I do it?
I have created GitHub repo with sample. If anyone could help me with it.
In UITableView I add UIView inside of UITableView and it stays there, but in UICollectionView it stays behind of UICollectionView. I want that it(UICollectionView sections) will stay under the UIView and on scroll all(UIView & UICollectionView sections) will scroll together.
There is no such thing as collection view footer or header, because the layout can be very different depending on your needs, but, you have a couple of function that can help you for example:
registerClass(_:forSupplementaryViewOfKind:withReuseIdentifier:)
or
registerNib(_:forSupplementaryViewOfKind:withReuseIdentifier:)
depending if you are using a nib file or not.
I'm not sure but you will also need to provide the height of the view in the layout delegate
UICollectionViewDelegateFlowLayout
you can do this by dragging your UIView on to your cellidentifier of UICOllectionView
Like i did see in snapshot:
here View is my UIView which i added to UICollectionView and it scroll with the CollectionView
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.
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
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.