UITableViewCell Silly Magic
source link: https://soffes.blog/uitableviewcell-silly-magic
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
UITableViewCell Silly Magic — Hi, I’m Sam
UITableViewCell Silly Magic — Hi, I’m Sam
Hi, I’m Sam
This is my blog. I also have a website thing.
UITableViewCell Silly Magic
Posted on January 23, 2012
Ever had a UITableViewCell
's imageView
not update when you set it's image
in a callback or block? It's amazingly frustrating. I usually end up going over and over the code to make sure it sets it on the main thread, the image isn't nil
, the image view is on the screen, etc, etc.
The Problem
UITableViewCell
s don't update when you set the imageView
's image
. UITableViewCell
's imageView
is magical and stupid. If you don't have an image in the imageView
, it will nil it out and remove it from the contentView
. When you set the image, it will cache it and do some silliness so your updates don't work.
The Solution
Make your own image view. Easy as that. Don't use the imageView
property unless you want it to work exactly the way Apple uses it in Music.app for albums. For anything else, just make your own and add it to the contentView
.
Trust me, you'll save yourself hours of frustration.
Always Initialize to Nil
Posted on November 9, 2011
Here's an excerpt from a great blog post on why you should always initialize your variables to nil
.
“Always initialize your object variables to nil, no matter what, because some day they may be captured by a block and if they contain junk when the block is copied you’re going to crash.”
It's just good practice, but this really sums it up. Thanks for the write up Ryan Perry!
© 2006-2022 Sam Soffes
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK