by V-2 · 12y ago · 0 comments
Yes, but if it's something like a ListView, don't put offset in array there, because the views are recycled (when user scrols), so you're likely to end up with corrupted data. I got bitten by this in the beginning. You can go to great lengths to prevent this from happening, but it will be hard for a reason, because that's abusing the design principles.
I'd recommend reading up on the ViewHolder pattern in this context.
Long story short: cache all the references to all specific sub-views of the row view in the tag (so you don't have to retrieve them again and again) - that's good practice. Just don't store any position-specific data in it.
Watch http://youtu.be/wDBM6wVEO70?t=9m50s - very informative
@property (nonatomic, strong) id context;
or
@property (nonatomic, weak) id context;
if you are sure the context will always exist.
http://blog.xebia.com/2013/07/22/viewholder-considered-harmf...
I refactored all my code after reading this, and now I consider the ViewHolder an antipattern.
It is incredible how much cleaner and readable my codebase is with custom views. And the performance is the same.
Number of times I have used view tags: Once.