UITableView edit mode appears on top of my views - ios

edit mode problem
As you can see in the picture, when I enter the edit mode the delete button appears on top of all the views in the cell.
I assume this is because I am using programmatic UI with autolayouts not the storyboard and some of the constraints are preventing actions, but I cannot find out how I can resolve this issue.

I suspect that when creating your UITableViewCell subclass, you did not add your custom subviews to the cell's contentView.
From the documentation:
The content view of a UITableViewCell object is the default superview for content that the cell displays. If you want to customize cells by simply adding additional views, you should add them to the content view so they position appropriately as the cell transitions in to and out of editing mode.
Sounds like your problem exactly.

Related

Unwanted UIView over UICollectionViewCell (TapGesture Doesn't work )

Recently, I see a strange thing in Xcode 11.4.
When I create a UICollectionView with Its cell, adding TapGesture doesn't work. By debugging on its view in runtime, I noticed a view covers all the cells. It seems it is ContainerView.
This view prevents users to click or tap on items.
Any help is appreciated
Are you adding your subviews and tap gesture to the cell's contentView?
In the documentation for UICollectionViewCell (https://developer.apple.com/documentation/uikit/uicollectionviewcell), it says:
To configure the appearance of your cell, add the views needed to
present the data item’s content as subviews to the view in the
contentView property. Do not directly add subviews to the cell itself.
The same applies for UITableViewCell as well.

Issue with Autolayout and StackView while using ScrollView

I a trying to create a UIScrollView that fits exactly the contents of its subviews. I do this with a StackView and the scroll view's height is determined by how much content there is in the stack view. Within the stack views, there are views that contain an UIImageView and a UITextView
The UIScrollView starts below the title view, however every time I want to add another view (which it should scroll when the content is bigger than the actual frame) there is an issue with the scroll view's Y position. This works perfectly if I only add UILabels and UITextFields, using the same procedure
How can I do it so I can programmatically add views on the stack view that includes an UIImageView and a UITextView, just as the View Controller with labels and textfields does.
You can download my app project at the following url
https://github.com/francisc112/DescriptionWithImageApp.git
Instead of a scroll view why don't you use a table view and create a custom cell with the stackview and its contents inside the cell and you can dequeue the same cell for adding multiple information.
I was not able to open your project
So I Tried opening your StoryBoard and Re-Viewing your constraints Applied , here is what I have Done Please check in following Link
Link - https://drive.google.com/file/d/1D-dzKsSqpx7dWsI5fYRdAfCMY_vENoIR/view?usp=sharing
View Hierarchy
Note - For such output I will prefer using a TableView instead of StackView as Same output can easily be achieved using TableView

UITableViewCell doesn't resize when UIStackView changes its arranged subviews

I'm using Auto Layout for my UITableView and it's custom cells. One of these cells has a UIStackView to which I add and remove arranged subviews, however, when its arranged subviews changes the cell itself does not resize.
Calling the reloadData() method is a fix for this problem, however, I only want to update the one cell that changes.
When I try calling reloadRowsAtIndexPaths(_:withRowAnimation:) however, it only updates to show the previous change on the arranged subviews. So for example, if I add one arranged subview, say a red one, then nothing appears to happen (even though the subviews are added when I check), then adding a second causes the cell to reload but only update to show the previous red arranged subview that was added and so forth.
Is there any way of forcing specific cells to layout in the UITableView?
Update: Here is a link to an example project showing the issue:
It seems the answer posted here works. I've opted for the non-animated version of the answer but both seem to work.

Button not responding in Table View Cell [duplicate]

This question already has answers here:
Programmatically send to front/back elements created from interface builder
(2 answers)
Closed 10 days ago.
I am using a .xib for my cell in a table view. Inside the .xib, is another view (cellBackgroundView), and a button. When I run the app, and click the button, it does not respond at all. Instead, it calls the tableView's didSelectedRowAtIndexPath method which brings another view controller.
Using Xcode's Debug View Hierarchy, I discovered that I have a view overlaying the all the buttons (see pic attached: this overlaying view is highlighted). This view (called backgroundView) that is overlaying my button is a View, within a view. I have a feeling when you place a view in a view, and put a button in the initial view, the button isn't called because its below the view hierarchy.
How do I fix this issue? Is there a way to move background view to the back of the view heirarchy so that the buttons will be responsive?
Debug View hierarchy:
Structure of .xib
Two things that you could check
1) Do you have a delegate method for cell height and is the height returned correct? Unless you have Clip Subviews on for the UITableViewCell, the contents of the cell can be visible outside it's frame, but the parts that are outside the cell's frame are not registering user interactions.
2) Is some other view element higher in the hierarchy (lower in the XCode listing you posted) overlapping the button? iOS Simulators Debug -> Color Blended Layers can help spotting this.
Edit:
If I interpret the added screenshots correctly, you probably have the issue mentioned in the option 1) above. If the other elements showing in the screenshot are those listed as subviews of the Cell Background View they are mostly outside the parent view's frame and thus don't receive touch events. If the background view's frame is correct, then you might want to move the other elements as children for Feed Cell directly.
Also, the element listing suggests that you are using plain UIView as the parent element. I don't know the inner workings of your application, but if you only use this view in a UITableViewCell you might want to consider making the parent view a Table View Cell in the xib. This will reduce some bloat and allow you to configure some properties for the cell in the xib.
Maybe you forgot assign your Button to code
I assume Feed Cell is a subclass of UITableViewCell, and cellBackgroundView is the property contentView of this cell.
If so, the cells property backgroundView should be behind your cellBackgroundView (the docs say: UITableViewCell adds the background view as a subview behind all other views and uses its current frame location.).
You could set the cells property backgroundView = nil, and see whether it is still there in the view hierarchy. If so, you do add a custom backgroundView on top of the other cells views somewhere.
To check this, you could read out the subview hierarchy of your cell in your method tableView:cellForRowAtIndexPath: with something like NSArray *svs = cell.subviews; (assuming cell is the tableViewCell) and set a breakpoint behind this statement.
svs usually contains first the UITableViewCellContentView, and above it the _UITableViewCellSeparatorView. The cells backGroundView will not be shown. You could check there your view hierarchy.
If by chance there is a custom backgroundView on top, you could - as a workaround, not a solution - bring the contentView to the front by sending to the cell bringSubviewToFront: with the contentView as argument. Then the button should respond.
In your Structure of Xib Place your button below the view that is first the view is added to superView then the Button, then your button will work.
or you can code
-(void)viewDidLayoutSubviews{
[self.view insertSubview:yourButton aboveSubview:cellBackgroundView];
}
Hope it will help.
Do you add an UIButton by code?
If so you should ensure you addSubview: into cell.contentView and not into cell.
Also you could try to apply CellBackground class to a view inside contentView, not directly to contentView.
you can use this method.
[cell.contentView bringSubviewToFront:yourButton];
after that if you want to back in background then tou can use sendSubviewToBack: method .
After adding this methods your button is not responding set the userIntractionEable of button's superview.

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.

Resources