Unwanted UIView Created Automatically with UITableView Cell - ios

I am working on an app in the storyboard and building the basic layout. I had a dynamic prototype cell in a UITableView which I created a view in because I thought it would be a good idea to constrain some items in the cell with a view. When I tried to delete that view, I could not. I could not even move any other views outside of it.
I deleted the entire cell and tried to make a new one but even the new one had the view in it, name name too. Everything I tried to put in the cell was automatically put in the view as well.
Now the view is causing me problems because it's height is static and everything is constrained by it. It also seems to take on the roll as superview since everything is inside of it. So any time I constrain anything to the super view, such as the leading edge to superview constraint, it will actually be constrained to the leading edge of that view.
Why is the view being created whenever I make a cell? I have a feeling that it is some setting I mistakenly set but I looked through all of the settings of the view and and cell.
How do I get rid of this view that seems to be tied to every cell?

Related

How to set Table view cell to occupy entire screen?

I am working on a project to get custom news feeds from Bing news. I created a custom table view cell and populated various UI items in it. But I am having a hard time to make it occupy the entire screen, it starts from extreme left and ends on the right, leaving large gap from the right margin as show in the image. Can anyone help me out, how to correctly fix it with a detailed explanation of how constraints work in Table views and Tableview cells.
Here' what it looks like in the simulator
Remove previous constraints and add constraint to your UITableView like as shown in below image.
So you UITableView will have 0 margin from edges.
Create a UITableViewController. Just drag drop a TableViewCell into it. Add identifier for that cell and use it. By default it will occupy the whole screen.
In your case I guess you might have added constraints to UITableView. Here what you should do is pin your UITableView to Top,Bottom,Right & Left or make UITableView's width equal to SuperView.

UICollectionView within UITableView. How to tell tableview cell to change height when collection view gets taller?

I have a UITableView and one of my table cells is a UICollectionViewController subclass that contains a UICollectionView of displayed email addresses. When a user adds an email the UICollectionView and it’s cell in the table view should get taller.
I’m currently attempting to do this setting my collectionView height constraint to collectionView.contentSize.height in the LayoutSubviews method of my collection controller/cell class. My issue is that the cell in the UITableView is not changing size when this happens.
I am assuming that this is because there is nothing telling the table view that the height of the email entry cell has changed. I am currently using dynamic cell sizing - or trying to anyway. Even, if I call tableView.reloadData() this still does not work. I’m wondering if someone could give me a high-level idea of how they would set this up.
UPDATE:
I had a broken constraint issue that was part of my problem, but this is still not solved. While have proven that I can update the height constraint and that will update the size of the collection view, it's out of sync. It's always one update behind. Here's an image showing the 'UICollectionView' in green and you can see in the logs that I'm updating the constraint (yes, multiple times) each time after adding a new item to the collection, but it is not updating the bounds of the view instance. In this example, if I were to add a new item to the collection, the next time I inspect bounds.height it would be at 149.5. What am I missing!?
i had answered this question in another tableview inside tableview cell that will work for collection view too ,i explained it in this thread
ask me if you faced any problem
It seems you want to set the height of your table view cell dynamically. This detailed tutorial walks you through making a custom cell class that will have dynamic height. Unfortunately, this tutorial only walks you through how to do this with auto layout constraints and a storyboard. In the tutorial you'll notice that the height of the cell depends on the constraints put on a title label within the cell. Try doing the same thing, but applying the constraints on the content in your cell (the collection view cell).
http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout

Removing a static UIView from a UITableView with Prototype Cells

I have a storyboard I'm maintaining that is a UITableViewController.
The UITableView is set to use Dynamic Prototypes and has 2 cells.
Above those two cells is a UIView inserted within the table view. That view contains a UIButton and another custom UIView. Both have constraints. The effect is that we have a table view with a button above it.
Now, in certain conditions, we want to remove that button and have the rest of the table view move up in the UI. I can remove that button -- by itself or by removing that parent UIView, but I cannot seem to to get the table to change the position of the prototype cells.
To hopefully make it clear, my document outline looks like this:
Table View
View (buttonContainerView mentioned below)
UIButton
View (child view mentioned below)
Constraints
Prototype Cell 1
Prototype Cell 2
I have tried several different approaches to remove the button. After reading that removing it from the superview will remove constraints as well, that's the approach I currently have in place.
[self.buttonContainerView removeFromSuperview];
I've tried removing the button, the child view, and the container view. I've also tried explicitly removing the constraints then removing the views. None of these seemed to work.
I've also tried the above with calls to setNeedsLayout and setNeedsUpdateConstraints on the table view, as well as setNeedsDisplay on the view.
I've also tried setting the row height to 0 for that first view, but it turns out it's not a UITableViewCell, so that doesn't work, either.
Of course, if I delete that container view from the storyboard, the prototype cells do appear in the UI exactly where they should.
Can you sense the flailing about?
What else could I be missing here to remove that top view effectively?
What I didn't realize is that the setup I have is a UITableView with a table header. To remove it and fix the spacing problem I was having I just needed to set self.tableView.tableHeaderView = nil in viewWillAppear:.

Removing subview from cell for auto layout issue

What is the best way to remove auto layout constraints for a Cell when a view should not be shown?
We have a cell which has a layout with around 6-7 views. One of those views is for a star rating. When the star rating is not available we do not want to show the view. At present we hide the view but this leaves the auto layout constraints in place.
Similar question - How to use auto-layout to move other views when a view is hidden?
This is the view in question hilighted above. We would ideally like to remove this view from its superview when there is no available star rating. The issue we have is that if we remove the view from superview removeFromSuperview in cellForRow... then the next cell would be affected, because the view is not added again.
(I would comment to request clarification, but do not yet have the reputation.)
Is there a chance you could just hide the view for the cell in question?
If I understand what you are saying, you are suggesting that removing the view in question from it's superview creates an issue when you are creating a new cell. So, when you dequeue a new cell, just check your star-count property, and if it is >0 for this next cell, then show the view for that cell.
Another option is to pin the surrounding views to their parent view rather than pinning them to this view that you want to remove. This way, when you remove the star-rating view, the layout constraints for the surrounding views remain unchanged.
remember the constraint (for show/hide a view) in to variable and remove it constrains.
and delete this constrains and replace with new constrains if you need change view.
For example:
view has width and height for show
and replace constraint where width and height will be zero for hide view.
The best route I found was to create separate cell layouts and decide which layout to use based on if the information was available. This meant creating a second prototype cell in IB without the view in question and different constraints but works as expected. Open to other suggestions on this one.

UITextView size not changing size after text has wrapped until second character is typed

I have spent at least 10 hours trying to figure this out and I am stuck. I am trying to have UITextView within a UITableViewCell that automatically expands to the size of the textview when the number of lines in the text view has changed. The table cell is inside a static table view. I have looked at almost every question about this on stackoverflow and nothing seems to be working.
My test project is here.
I have created a custom class that automatically resizes the textview. It works perfectly when not in a table cell. You can see this in the example project. There are two instances of the textview; one in a regular view where the textview resizes correctly, and another in a tableview. In the table cell, it doesn't resize until the second character on the next line has been typed. It is odd, because when I log the height of the textview it says that the value of frame.size.height has changed but the text view does not change size.
One thing that worked was creating a custom table cell and then overriding the layoutSubviews method but the problem with that was the bottom border line on the table cell lagged and created an ugly line across the screen. I looked for a solution but could not figure out how to prevent this.
Thank you for taking the time to read this.
I have tried your project and make it work by :
In Tbl View Controller in storyboard, remove AutoLayout. Although you don't set any constraint for the text view, at run time some constraints will be set automatically, and that will clash when the text view tries to change its frame.
In storyboard, set the autoresizing mask of the text view to default (Fix top, Fix Left, flexible right margin, flexible bottom margin).
It will work correctly now.

Resources