I'd like to be able to dynamically change the first cell of my UITableView.
Basically, when I'm scrolling, I'd like the first row to be "highlighted" when it is scrolled to first visible position in the table. I found at least one way involving
indexPathsForVisibleRows
and
reloadRows at:indexPath:
but the results are less than optimal.
Is there a clean way to achieve this?
As I understand that you are creating a thing that look like dateTimePicker/Picker. So, I think the implement are the same between these. First, Delegate from scrollView must be handle to know when will the TableView is stopped scrolling. Then, we have to snap to the first cell visible fully visible (in case it just visible a little bit). Then we need to update that first cell to hight light. Hope this will help you.
So, my problem is pretty simple. I have a UITableView in a UIViewController. The tableview has dynamic cells (custom cells with images , text, etc.. from a subclass I created) and these cells belong to a subclass I created. Everything is going fine since the content is different on each cell. The problem is that when I scroll the scrollview of the cell which is horizontal ( I have a UIScrollView in the subview of the cell. I created this scrollview on the cell subclass), on let's say, indexPath.row == 0, and scroll the tableview vertically, after about 8 cells, the ninth cell has the scrollview scrolled as well. This is because of dequeuereusablecells, so the ninth cell is actually the first one, only displaying different content but since it is the first cell, it has the same background operation (the scrollview scrolled).
I tried to unscroll in the cellForRowAtIndexPath: but although this solves the problem it creates another : The first cell that was scrolled is not anymore. So, to solve this new problem I am planning on adding a workaround here that is a dictionary of [Int:Bool], that is, the indexPath corresponding to a Boolean value. If I scrolled the first cell, then 0:true. If I reach the ninth cell (which is equal to the first cell, but with IndexPath = 8 ), I unscroll the cell's horizontal scrollview. If I come back to the beginning of the tableview and reach the first cell, I scroll the cell's horizontal scrollview back. What do you guys think?
The other workaround I can think of is just not use dequeue reusable cells since I don't think I will have more than 30-50 rows on my tableview.
In terms of performance, which operation is better?
Firstly, I would suggest you to carefully analyse whether removing scrolling offset from the first cell is such a bad idea. If I am a user and I scroll down to the very bottom, making the first cell invisible, are you sure that I want it to return to the scrolled position after I scroll back to top? The answer might be Yes, but you should think about this carefully because it might lead you to the simplest solution.
However, in case you really need to do it, I would have a variable which stores the state of the scrolling for each row. If you have an array of objects from which you pull necessary properties (title, image etc) you can add this as an extra property to these objects. Otherwise, you can create an array which will be storing this info (I would prefer an array over dictionary for this task).
Fundamentally it's an issue caused by table view cell reusability. You can have workarounds, but I'd say that, things that aren't supposed to be reused should not be reused.
If your cells are all similar (with minor differences), you could use just one cell identifier; If you have very different types of cells, say, one type has a horizontal scroll view inside, one type just has some labels and images, you might want to consider to have two identifiers, so cells that have UIScrollView won't be reused for normal cells.
And at the same time, you can still do necessary cleanup works in prepareForReuse: to make sure cells that just get dequeued have a fresh start.
I'm having a problem with UITableView section animations very similar to this post. Unfortunately, no one seems to have found an answer for this.
I have a table view with multiple sections that expand and close when the first cell in each section is selected. There no adding or removing of cell, just collapsing and expanding the section.
My problem is that the sections' header titles are flashing white momentarily before returning to normal, whenever the following method is used.
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation: UITableViewRowAnimationAutomatic];
Only the title of the section being collapsed is flashing white though. Has anyone else had this problem or found a solution?
I'm using this same design in another table where this is not an issue. One thing to note here though, is that my cells are a custom subclass of the UITableCell and are larger than the first cell that is used to collapse the section.
Maybe something about ios laying out the cells on section animation is making the section header title flash white?
I can post a code example it it'll help.
(Update below)
When I delete items from a section in my collection view (say, section 0), I find that the supplementary views (in this case headers from the UICollectionViewFlowLayout) pop into place as the cells from section zero animate away and a 'duplicate' of the latter sections animates in with them to match the ones that have popped in.
Naturally the ones that pop into place could be the 'duplicates' but it doesn't really matter. It's like the collection view can see the future! and then is catching up with itself. That's how the animation feels.
Do you know if there is some quirk or bug or easy fix to suppressing this extra popping supplementary view?
Update: I've noticed this also occurs with the cells, not just the sections, and it seems to 'double' the bottom few cells and sections on the screen. When I delete cells from the zero section, a handful of sections and cells below it animate properly without duplicates, but beyond a certain point, they pop. A constraints issue?
This is a bug with UICollectionViewFlowLayout. For whatever reason UICollectionViewFlowLayout cannot properly animate cells that are not on screen.
I've done two workarounds that address the issue but none solve it completely. The first is to artificially increase the frame of the collection view so that it creates the cells needed for animation, and thusly animates correctly upon data change. This is a bit of a hack and doesn't work for all cases.
The other option is to write your own flow layout from scratch. This works for me and complexity is entirely up to how complex your layout is. Here is an example I used for writing my own flowlayout: https://github.com/chiahsien/UICollectionViewWaterfallLayout
I am trying to configure my CollectionView to have one section be differently sized than the others. I have two sections. Lower part should show a number of cells simultaneously and the upper section should only show one cell at a time but be scrollable to reveal more cells one by one.
I tried to play with the .frame property of the CollectionView but obviously it is not the right approach as it changes the appearance of the whole view.
I also tried to retrieve the FlowLayout object and see if I can get it from there. Did not find a way.
Neither the section Insets are the answer so far ...
It is simple to use two uicollectionviews for upper and lower section, instead of using only one.