3

UITableViewCell Silly Magic

 2 years ago
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.
neoserver,ios ssh client

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

UITableViewCells 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!

Continue reading →

© 2006-2022 Sam Soffes


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK