views:

55

answers:

1

I am display some long text in a cell, and resizing the height of the cell using heightForRowAtIndexPath. However, when the text is displayed it is running into the area used by the (blank) disclosure indicator.

When such a row is selected, and the checkmark is displayed, the text reformats itself to not use the indicator area, causing a visual effect I do not want.

If there was a UITableViewCellAccessoryBlank accessory type (rather than UITableViewCellAccessoryNone), maybe the text wouldn't wrap into that area when displaying. Am I going to have to create a custom cell and layout my own label, or is there a simpler way?

+1  A: 

Hi Bill,

First of all, I don't see a property call UITableViewCellAccessoryBlank in the UITableView Cell class reference so I don't think this will work.

I think you have 2 options :

  • Create a custom cell, like you suggest.
  • Configure the textLabel of your cell to change his contentMode.

I read this in UILabel class reference :

The default content mode of the UILabel class is UIViewContentModeRedraw. This mode causes the view to redraw its contents every time its bounding rectangle changes. You can change this mode by modifying the inherited contentMode property of the class.

I suppose that the textLabel bounds change every time you change the accessory type, so by default it redraw himself.

You can try this in your - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method :

cell.textLabel.contentMode = UiViewSomeContentMode;

Content mode list can be found here. I'm not sure which one you should use so I let you try.


EDIT

It seems that contentMode is not working. So you should use a custom UITableViewCell to prevent any animation when adding an accessoryView.

Hope this helps !

Ermiar
@Ermiar - There IS no UITableViewCellAccessoryBlank. I was just surmising that if there WAS then maybe the contentView would size itself to consider the area of the accessory unavailable. The problem I am having is the text runs all the way to the right boundary of the cell. This is fine if there is no accessory indicator, but when the user touches the cell, I want to then display the checked indicator. The indicator displays ok, but the text has to reformat itself to fit, which just doesn't look visually appealling. I'm hoping to avoid the reformatting animation.
Bill
Did you try to use the contentMode of cell.textLabel ?
Ermiar
@Ermar - Yes. I couldn't see how they would help, but I tried a bunch of them without any discernible difference. The docs say this attribute is used to determine how a view lays out its content when its bounds rectangle changes. I want to prevent the width of the textLabel from changing whether the accessory indicator is present or not, not worry about how the content is displayed within the label.
Bill
I think in this case you should create a custom UITableViewCell from a nib for example. I'm sorry that the content mode didn't work. I edit my answer.
Ermiar