Tableview cell does not cover the whole area as expected - ios

I've been googling an answer for this for hours but cannot find anything that actually works in my case and I've no idea why.
I'm creating a tableview which should be from the top of the tableview to the bottom of the tableview, but in this case it doesn't.
img here
In this image you can see how it looks like in the storyboard (Which is also the way I want it to look like), you can see it almost cover the whole tableview.
And this is the result:
result of tableview
I'm trying to make the tableview cell start from the top and contain all the way to the bottom of the tableview (Well, like the storyboard image)
I've added this...
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return 410
}

You dont need to use UITableView
You add vertical scrollview and add one contianer UIView in it then you can add mutiple UILable and UITextField one bellow another.

Related

How to set header exectaly above the particular content in tableview

I used checkbox and switches in my custom tableview cell. But as shown in the image i need to place the header at the proper place above the checkbox and switch.
How should i suppose to do this.
Thanks in advance.
Follow these steps for achieving your task.
Add a UITableViewController to your storyboard
Create two cell in your UITableView
First cell identifier take as headerCell and second cell identifier take as listCell
Take two label inside your first cell
Now it's time to set constraint first controller click on right label and drag it to first cell and set it to vertical center.
Now click on same label and set its constraint from left as 8 as shown in image.
Set same for Label two which is Selectable.
Now comes with the new cell which is called as listCell see the image and set all constraint as shown in image.
Also don't forget to set width to both label which in header cell.
You would probably need a custom tableview header as well.
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return YOUR_CUSTOM_HEADER_VIEW
}

UITableView inside a UITableViewCell in iOS

Hello I want to create a UITableviewCell like this.
There can be 1 or more attached documents.How can I show attached documents if there are more than 1 documents.
Can I use a A UITableview inside the UITableViewCell? If so how? What is the best way that I can achieve this?
Please help me.
Thanks
A vertical scrolling inside a UITableViewCell would be kind of strange and complicated because you can also scroll in the normal table view. Wouldn´t it be a better solution for you to set the height of the cell depending on the number of attached items. One pseudo example:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return cell.attachedItems.count * 50
}
Then a cell with more attached items would be bigger and you could keep the normal table view scrolling flow.

UITableViewCell height from initial size to full screen

how i can swipe down (scroll) one cell from my tableviewcell (static cells) and make this cell fullscreen?
I know how make the cell full height:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.frame.size.height;
}
But how i can start this cell with a fixed height and after swipe down (scroll) the cell, make the cell fullscreen?
Thank you
The way I do this sort of thing is actually to treat this as a master-detail interface. The gesture does not really expand the cell; it does a "push" of another view controller containing the full-screen version. And it does it with a custom transition animation, so that it looks like the cell is expanding to form the full-screen version.
And the same thing when returning (popping), in reverse.
This is an example; it isn't 100% identical to what you're doing, but it shows how the push-plus-custom-animation can give the sort of effect you're after:
You can also monitor frame changes in your cell class and expand when the cell is pressed, (not scroll if that's what you really want) and by monitoring frame change you can expand the cells height. Let me know if you want more information because this is on selection, not on scroll.

Auto size of table view cell does not appear to work in a standard UIViewController class

I have created a test project in order to verify this problem. In the project storyboard I have two scenes. One scene is based on the initial ViewController that was added to the single view application when the project was created. The second scene was created by dragging a UITableViewController onto the storyboard.
In both scenes, I believe I have configured the prototype cell so it should auto size. When I set the initial ViewController to the one based on the UIViewController, the UITableViewCell do not show / size correctly. (See below)
However, when I set the initial ViewController to the one based on the UITableViewController, everything works fine. (see below)
The code / project is very simple and I am hoping someone has seen this and can tell me why the auto size for the UITableViewCell is not working correctly when the class is based on UIViewController verses a UITableViewController. Any help would be greatly appreciated. It appears I cannot upload the project here so I will try to get it uploaded to another location and update the question with a link.
To answer standard questions
Both prototype cells have two UILabel in them
The first UILabel has left, top, right and bottom constraints specified.
The second UILabel has left, right and bottom constraints specified.
Both classes set the estimatedRowHeight to a number and the rowHeight to UITableViewAutomaticDimension
All UILabel have their lines property set to 0
The first UILabel in both scenes has its Line Breaks set to Word Wrap
The second UILabel in both scenes has its Line Breaks set to Truncate Tail.
Below is a screen shot of the scene in interface builder. Left is based in UIViewController, right is based on UITableViewController
Here is a link to the code I hope: Sample Project
So I have found the "silver bullet" that seems to resolve a great number of challenges regarding auto layout of prototype cells.
In the cellForRowAtIndexPath function I added the following line of code right before I return the cell:
lobj_NearbyLocationEntry!.layoutIfNeeded()
(lobj_NearbyLocationEntry is the name of my cell variable I am returning.)
When I do this, the auto layout for my table works fine. On a side note, I found a defect in the code that uses the UITableViewController also. Once the data loads and it all looks good, if you scroll down and then scroll back up, you will see a couple of the cells are now not laid out correctly. Putting this line of code in that view controller's code also resolved that layout problem.
I hope this helps many people who are sitting there trying to figure out why their app is not auto laying out a tableView cell correctly. :)
For Me It Works
Give upper UILabel (right,top,left) constraints
Give lower UILabel (right,top,left,bottom) constraints
In Custom UITableViewcell
override func awakeFromNib() {
super.awakeFromNib()
up.lineBreakMode = NSLineBreakMode.ByWordWrapping // Label outlet
down.lineBreakMode = NSLineBreakMode.ByWordWrapping // Label outlet
up.numberOfLines = 0
down.numberOfLines = 0
// Initialization code
}
EDIT
InUITableViewController
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
In UIViewController
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

How to make UITableView appear from bottom to top when scroll?

I'm looking just for general scenario.The idea is when app launches user can see only first cell of UITableView at the bottom of UIViewController. When user scrolls up full table appears and when scrolls down only first cell is displayed again. Something similar like keyboard in Facebook messenger app, but with tableView. For now I added tableView as subview to scrollView, but problem is tableView appears from top to bottom, and I'm looking for solution how to make this work upside down.. So, tableView have to appear from bottom to top of UIViewController.
My idea would be:
Give your UITableView the desired frame at viewDiDLoad (probably the height of 1 cell, at the bottom of your UIView)
Let your UIViewController implement UIScrollViewDelegate
At - (void)scrollViewDidScroll:(UIScrollView *)scrollView of UIScrollViewDelegate check which element is scrolling (if its your UITableView) and also check which direction user is scrolling
Change the frame of the UITableView as you wish, you will also have to come up with some logic to block further changing of the UITableView's frame (a BOOL would do good here I guess)
Not sure I understand your correctly but, maybe, this will be helpful
I believe you can try to add zero cell (or first section header view of your UITableView) with transparent background. So that your first cell will be placed on the bottom of screen and UITableView height will be equal to screen height.
In this case, you will have only one scrolling view (UITableView, in particularly). Following method can be used to perform expandable animation and scroll table to top to hide zero cell when user taps on first cell:
[UITableView scrollRectToVisible:animated:]
After that you can leave UITableView as it is and "constrict" your table whenever you need in the same way as it was expanded before.
I understand what you want to do.
In general, UITableView shows cells from top to bottom.
You can add transform in tableview:
tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
Then your tableview will show the cells from bottom to top and you can scroll tableview from bottom to top.
But cells will be transformed as tableview, so you have to add same transform to cells also.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")
**cell.transform = tableView.transform**
return cell
}
All done. Hope to helpful!

Resources