I have Trailing Swipe actions set up for my table view. And everything works fine, until I delete a cell, and then the cell below it has its trailing swipe actions overlapping with its cell when it's swiped over, rather than swiping over the actual cell to present the trailing swipe actions.
Some notes that I've discovered:
- Only the cell directly below a deleted one is affected.
- The cell is only affected for a little bit of time, or until the user scrolls the table view up and down. But it's still a big issue in actual use given that typically people will delete their cells in rapid succession.
I've taken a screen recording an put it on Youtube:
https://www.youtube.com/watch?v=a_8JuLFrfyE&feature=youtu.be
I have tried controlling when the table view enters and exits its updating via .beingUpdates and .endUpdates, but that made no difference.
And I tried reloading the problematic cell, but that didn't help and made the cell flash. I also tried scrolling the table view just slightly after a deletion, but that didn't help either.
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
// The configuration of the cells isn't very important, but it's more so an issue just when deleting cells that have trailing swipe actions.
}
Related
Hi I have been trying to add an Activity Indicator, or a Loading spinner, to the bottom of my collection view. I have searched online on how to do so but there is not a clear way to do so.
I do not want to use a cell for the indicator itself because my cells a pretty big. (2 cells take up the whole screen.) So I would just like to have a small loading spinner at the bottom for when users scroll down.
Through the research that I have done I have seen that some people use this function below and a separate class to build the spinner.
private func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) -> UICollectionReusableView{}
But I do not know how to use it. I already created a class called LoadingViewController() but in all honesty don't know if it is event he right type. Currenlty I have it set as a UICollectionReusableView
For a little more background, I already added the ability paginate data. So when I scroll down the collection view, new cells are loaded. Now the problem is I want to show a little spinner at the bottom when the data is loading because if not the app stutters and looks like it is broken.
Or is there a better way to show load items in a collection view that does not cause the scroll to freeze?
Please let me know if you have any questions regarding my situation I'll try to answer them to the best of my ability.
I am making a to do list app and have 3 custom cell types. For task cells, it is just an imageview on the left and a textview on the right. I would like the cell to automatically resize itself when the textview text is to large for a single line.
I have added the correct constraints and have added this to viewWillAppear
tableView.estimatedRowHeight = 30
tableView.rowHeight = UITableView.automaticDimension
However, when going into the view with the tableview, the cells remain small for a second and then expand to their correct size. Also, when initially adding the task, the cell doesn't resize unless either going back and opening the view controller again or the tableview is scrolled up until the cell is out of view and then letting go.
This is very odd behaviour and even happens when removing the two lines above from viewWillAppear. It just happens for no reason.
I would like the cells to be of the right size when going into the view and not resizing a second later.
An example of what this looks like is below
Okay so I finally found the answer. I made my cell programmatically with auto layout and some of that was setup in the layoutSubviews() method inside the cell. This method is only called when needed. So when scrolling up or down.
To fix this, in your cellForRowAt method, just call
cell.layoutSubviews()
Hi guys, please give me an idea how to create a list similar to the homepage of iflix (image attached below). I tried using table view with collection view inside the cell, but I don't like the performance because it flickers when I scroll because of the reloading of collection view cell.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell") as! Cell
cell.bind(data: self.datas[indexPath.row])
cell.collectionView.reloadData()
cell.delegate = self
return cell
}
When I removed the cell.collectionView.reloadData() the scrolling is smooth but the displaying of data is incorrect because cells are reusing.
Can anyone give me a better idea on how to implement a layout like this? Thank you in advance.
there could be a variety of reasons why you are experiencing flickering, in fact the first release of that ViewController had the same issue on older devices. I would recommend first Analysing your app using the Time profiler to investigate the cause of the flickering you are experiencing. It’s very likely, as we discovered there there is not one main cause but a collection of smaller issues that when added together on the main thread causes the flickering. Below I will detail a brief description of how we manage to reduce the flickering effect.
The ViewController contains one vertical collection view, each row is its own cell that owns a horizontal collection view.
One thing we try to ensure is that drawing a cell is as efficient as possible. All cells and views are configured via ViewModels which for our case is a PODO (property only data object).
The ViewModels can be easily preprocessed on a background thread and contain e.g url, titles, hide/show buttons, cell sizes etc for any orientation. Plus it makes it very easy to test. We ensure that all images are the correct size so there is no time required to scale the image, along with that each visual item is opaque and rasterised to the correct screen scale. We also found for our code that if each cell uses ‘preferredLayoutAttributesFitting’ that can help to reduce the flicker also.
The next part is to try to help reduce the amount of effort taken to when calling reloadData. If each cell in the row is the same size then using UICollectionViewDataSource can be more process intensive than setting the item size, instead you can set the itemSize in the xib/storybaord or use a UICollectionViewFlowLayout. Before a cell is shown to the user the methods “collectionView cellForItemAt” and “collectionView willDisplay” will be called, you can try and split cell configuration work over those two method calls.
I hope that helps.
Description:
I have a list of UITableViewCells that have each have a UICollectionView with X amount of UICollectionViewCells (see image below for more clarity)
The idea behind this is to be able to implement sections with a header on top and a horizontal scrolling UICollectionView
Everything is working great, except when I try to focus the UICollectionViewCells (aka: CategoryCell). The UITableViewCell gets focused and highlights all the content making it impossible to focus any of the UICollectionViewCells.
What I've tried:
According to other posts the fix for this would be deactivate User Interaction and/or set the selection style to none on the UITableViewCell:
cell.selectionStyle = UITableViewCellSelectionStyle.None
and to enable User Interaction on the UICollectionViewCell instead.
Here are posts that talk about it:
UITableViewCell with UITextField losing the ability to select UITableView row?
How can I disable the UITableView selection highlighting?
I've attempted to implemen these solutions without success.
Question:
What step did I miss? Does the fix not work on tvOS? How do I focus my UICollectionViewCell that is in a UICollectionView that is in a UITableViewCell?
More:
Image showing my UITableViewController and all it's contents from my StoryBoard.
The problem is most likely that your table view cells are returning true to canBecomeFocused. You can disable that by either implementing the UITableViewDelegate method tableView(_, canFocusRowAt:) to return false, or by subclassing UITableViewCell and returning false from canBecomeFocused.
The focus engine will try to focus on the top-most view that returns true from canBecomeFocused, which is why it can't find your collection view cells: they're "hidden" inside the focusable table view cells. If you disable focus on the table view cells, then the focus engine will be able to find your collection view cells.
override func tableView(tableView: UITableView, canFocusRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
I am trying to change the default left minus icon for a cell in edit mode.
I tried everything.
I am already able to change the Delete confirmation button on the right, I need only to change the left icon.
I tried to create a custom interface cell and added a custom image on the left side, then I have added this code in my view controller.
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.None
}
Adding that code gives me a way to hide the minus default icon and showing my own image.
The problem is that the space for the default icon remains anyway :(
I do not know what else to do. I tried using constraints in my custom cell interface, but it does not fix the issue at all.
Also when using that piece of code anyway, not only the icon goes away (that's fine apart from the white space that it leaves) but also does not show anymore the right actions when swiping. Only the drag and drop feature reamains active.
func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
add this function so the rows wont indent while editing