Recreating the whole UICollectionView vs invalidating the UICollectionView layout on an orientation change - objective-c

I have a horrible problem that is worthy of a separate stackoverflow question. Perhaps I can save time by asking a different question:
What are the downsides to recreating the whole UICollectionView layout on every device rotation rather than invalidating the UICollectionView layout with invalidateLayout?
Bare in mind that its a small view with a maximum of 6 text based cells - not a lot of data.
This question is a follow on from this one. I implemented the UICollection view and everything is working except the first two buttons inside the cells aren’t changing width on a orientation change, its a mess. Its almost like the method to update the cells is definitely being called but with the data from the last orientation view. Even after lots of debugging I'm still unsure exactly what the problem is.
Update
I managed to solve my nightmare with the information from this answer and the actual code from this answer. But if someone can still answer this question it would be helpful and interesting, I still want to know the answer!

Related

Implement "sticky" section headers when scrolling in iOS

This implementation is similar to a normal UITableView, but with one caveat that drasticly changes the complexity of the work in my opinion. The ask is that all section headers will be visible at all times, no matter how long the table is.
Explaining the exact UX is a little difficult, but if you follow the link below there is an interactive example of exactly what I would like to accomplish in native iOS:
http://slinky.iclanzan.com/
It is my understanding that utilizing the normal UITableView will not be enough to satisfy this case. Aside from using a mashup of multiple TableViews, ScrollViews, and/or CollectionViews, I was wondering if anyone knew of some existing libraries that already perform this implementation?
Or if anyone has any high level suggestions on how to accomplish this with custom code that would be appreciated as well (Not looking for someone to write this all out for me, just an idea would suffice).
Found a solution after working with some teammates on a POC. I'll at a high level explain the implementation.
We know that a tableview's header and footer will remain static while we scroll. Since we want our sections headers to "stick" to the bottom and top of the tableview, we mimic this by dynamically adding any section header views that would have been hidden to the tableview's own header or footer.
We do this by maintaining an array of section header views, and calculating in layoutSubviews when we need to change the tableview's header and footer.

Prevent NSOutlineView (or NSTableView) from redrawing on scroll

It seems that my view-based OutlineView try to re-render text every time user scrolling. I think that was because it tried to save memory by re-using rows that fall outside of visible rectangle, then re-render new data to those old views. How can I disable this? I'm willing to sacrifice memory to archive this so that I can get better scrolling performance. (I have tried with various optimize like layer or so, but no luck).
EDIT: There is another question with same purpose as mine here How to make NSTableView not reuse TableCellViews, but no answer yet :(
I think you are confused -- it doesn't re-render the text. The table only shows views for the visible area (caveat below), and pulls in new views as you scroll -- potentially re-using old views.
You provide the view. Use the delegate method viewForTableColumn:row: and return your own cached view for a given row.
But that isn't going to prevent drawing; the view will likely still get marked dirty and draw.
I don't think you are asking the right question. It sounds like you have a performance problem. To help you with that, we'd have to see samples or instrument traces.
Caveat: Responsive Scrolling will pull in views that are in the non visible area. See the AppKit release notes about this.
corbin

How can I fix the flicker occurring when selecting an NSCollectionViewItem?

I've got an NSCollectionView which houses three columns of NSCollectionViewItems. In each of the NSCollectionViewItem prototype views, I have a single NSImageView. As far as I'm aware, this is a fairly standard setup. I think the problem stems from my use of a popover to present the collection view, but I'm honestly not sure. Basically, the problem I'm having is that when I click on one of the aforementioned NSCollectionViewItems to mark it as "selected," every once in awhile it flickers/flashes. It's not a total deal-breaker, but it's annoying enough to make me post this question.
Coming from the HTML/CSS/JS game, I started to think of all the ways I would prevent the flicker when building stuff with web technologies. My first thought was to make certain parts of the NSCollectionView (and subviews) layer-backed. I figured that by doing the drawing via layers or just setting the collection view to be layer-backed period, it would render better, kind of like GPU-enhanced animations in CSS (e.g. no sub-pixel antialiasing, enables z-depth, etc.).
So, I subclassed NSCollectionView and added a [self setWantsLayer:YES] in the
-(id)initWithCoder:aDecoder method. I was right! It removed the flickering altogether. Also, the scrolling became much smoother. However, in the process of making the flicker go away, everything else started messing up. The popover would take about 10s to load (vs. ~500ms originally), items would do weird overlapping things, etc.
My question to you all is this: what should I do? If anyone could help a brother out, I'd really appreciate it.

UTextView autocomplete vs live suggestions iOS

If I turn the autocorrection ON, the words get autocompleted, as if I write "wor", I get "word" before I finish writing. I don't want this to happen because I might be writing "world" or any word different than the autocompleted one.
I set Correction off in the Interface Builder and this problem is solved.
The problem now is that I still need the suggestions that appear in a little popover below the incomplete words.
This two features might be different but I don't know how to activate the suggestions.
How can I solve this?
This can be solved with the use of tableview. Create a tableview with the width as of the width of the textfield and height as you like. Place it just below the textfield. Make it hidden initially. When the user starts typing, fetch the array of data that resembles to the typed text and if any exists then, unhide the table view. On the subsequent typing keep on reloading the tableview sections with animations. You should be accurate on hiding, unhiding and then reloading the data on the tableview. I have implemented such thing before. It is really easy and once you get started with it you find it easy.
In the UITextView TextViewDidChange I created a thread that changed the cursor position. This, off course happens after the text view changes. The change of the cursor position triggers the autocomplete without letting me even see that there had been a suggestion.

Extended NSTableView

I would like to make a table-view with expanding ability.
When you press a row, the row should expand to show options like delete, copy and so on.
I have found an example for iOS, but I didn't get it running on Mac OS X, because NSTableView and UITableView are very different.
http://www.cocoacontrols.com/platforms/ios/controls/kofiles
Has anyone another template?
Or maybe even get this example running on Mac OS X?
I don't have code to hand you but you can use a view-based NSTableView. Your prototype view can resize itself to include controls if it's selected. All that's a bit complex to condense into a reasonably brief answer but if you use a view-based table view and treat the prototype view like any other that would grow and show extra controls, then wire this behavior to the selection state, it should work.
Note: you will have to write some code for the expansion portion, to handle resizing it, showing the controls, and notifying the table view that one of its rows changed height. Lots of documentation and examples exist out there for each individual component of your problem. Post more specific questions as you run into roadblocks.