UITableView inside a UITableViewCell in iOS - 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.

Related

Tableview cell does not cover the whole area as expected

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.

How to resize UITableViewCell height by showing and hiding components using auto layout

I have 4 components in my cell.
UIView
UITextView
UIImageView
Another UIView on top of the UIImageView
UIView
UIView
These content can be changed according the data that comes from the server(Sometimes it needs to hide the 3rd image view, sometimes 5th UIView). I'm using auto layout and with the auto layout what is the way to change height of the cell?
You can achieve this easily by using UIStackView. Stack views are a powerful tool for quickly and easily designing your user interfaces. Their attributes allow a high degree of control over how they lay out their arranged views.
Here is link for tutorial - Tutorial
If you hide a view from stackview it conveniently disappears from the layout, but it's still a subview of the stack view. So you don't have to do anything special if you want to bring it back later on. And by using self sizing cells, cells will automatically expand or collapse based on stack view height.
Do following steps:
When you hide any component give that component frame height as 0 and reload tableview. If you giving any component constant height then take outlet of height constraint and make it zero and specify its constant height again when you unhide.
When you unhide give him specific frame height and reload tableView.
heightForRow must returnUITableViewAutomaticDimension
As you already taken components from the storyboard so compiler understands the height of cell and work accordingly.
If you still facing issue you can ask.
this two methods are use for dynamic cell height
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
I post this for other man meet my issue.
Do not apply any change that will change the cell height in layoutSubviews, like hidden view or change any view's height.

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.

Dynamically updating cell height without having to scroll Swift

By default the height of my cell is set to 140.
But if expanded, it should be set to 265.
This is what I have:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
if(expanded){
return 265.0
}else{
return 140.0
}
}
The problem is, I need to scroll down, and scroll back up for the cell to change height. How do I fix this?
Secondary question (more interested in the above question, just if anyone happens to know)
Is it possible to have the cell animate from height 140 to 165?
Thanks
You need to reload the table view after you change anything in it like so:
tableView.reloadData()
When you scroll away from the cell, if it goes off the screen it is unloaded. When you scroll back up, it reloads it. You are basically just reloading the data as scrolling would do.
This code should work here:
tableView.reloadData()
It will reload the table everytime you changes something.
Source

How to make UITableViewCell display fullscreen (allow paging)?

I have a custom UITableView - Scroll, Paging Enable. Because each of my cell has one background image, I want each time I scroll up or down it will display each image as full screen. I try to make my UITableViewCell to be full screen (stretch its height as big as the tableview).
However, I've got a problem: when I scroll(paging), the cell doesn't display as full screen. It contains a small part of the next cell. Then the part of next cell increase bigger and bigger each time I scroll(paging) down.
I didn't see any Auto Layout Option for UITableViewCell, cannot add constraint to the prototype cell. Would you please suggest me the way to do it? Thank you very much.
i just add this two lines of code and it works for me
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return tableView.frame.size.height;
}
// ***** The following SWIFT function expands the cell image view to full screen (frame.size.height), adding to M.Salah's reply above.
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.frame.size.height;
}

Resources