Reputation: 20657
I am new to iPhone programming and working on my first real application (i.e. one not written in a book or online) and I've run into a small problem which I could solve a multitude of ways, but feel like there should be a good solution that perhaps I am just missing.
Here is the scenario: I have a UITableView
with a bunch of standard UITableViewCell
s in it. What I want to do is toggle a green check mark when the cell is selected and I have that part working (note: I'm already using the accessoryType
for something else, so I can't use it for the checkmark...besides, it's not as pretty). Unfortunately, when I toggle the checkmark like so:
if (...) {
cell.imageView.image = [UIImage imageNamed:@"checkmark.png"];
} else {
cell.imageView.image = nil;
}
It makes the cell's label bounce back and forth depending on whether it is checked or not. What is the proper way to align the cell's text (set via cell.textLabel.text
) regardless of whether or not it has an image set? The solutions I have come up with are:
Suggestions? Thoughts? Comments? Thank you very much :-)
P.S. I'd like the solution to work with OS 3.0 and 4.0 if that makes any sort of difference.
Upvotes: 0
Views: 822
Reputation: 53659
Option 1 is the way to go for a standard cell.
Strictly speaking, you do not have to subclass UITableViewCell to customize the layout. You can add any views you wish to the contentView. So you can add a UILabel and UIImageView to the contentView instead of using the imageView and textLabel properties.
Upvotes: 1