Re: [iPhone] UITableView cell display bugs ?
Re: [iPhone] UITableView cell display bugs ?
- Subject: Re: [iPhone] UITableView cell display bugs ?
- From: Steve Christensen <email@hidden>
- Date: Mon, 20 Jul 2009 06:32:06 -0700
From what you've said below, you probably should be creating a
custom cell type based on UITableViewCellStyleSubtitle and add the
third label to your class. At least in NSTableView (I haven't yet
played with the iPhone), a cell class determines what is drawn at a
particular row/column location. Right now it sounds like you're
fighting UITableView rather than working with it.
On Jul 20, 2009, at 1:35 AM, WT wrote:
I'm trying to reuse (with some modifications)
UITableViewCellStyleSubtitle cells, which have two left-aligned
labels. I want to have both labels and add a right-aligned text
field. All three views must be as wide as roughly half the
available content view width.
It should be a trivial task: just add the text field to the cell's
content view, and resize all frames. The problem is that the detail
text label is stubbornly obscuring the text field, even after being
resized and sent to the back. (see attached picture)
I realize that any frame adjustments must be done in -tableView:
willDisplayCell: forRowAtIndexPath: rather than in the method that
creates/reuses cells, but I wasn't expecting the order of content
view subviews to change between those two methods. I verified that
bringing the text field to the front in -tableView:
cellForRowAtIndexPath: has no effect because the detail text label
is brought to the front between that method and willDisplayCell.
Maybe there is a reason for that, but I don't see it.
But there's more...
In the willDisplayCell method, I resize the text field and both
labels, bring the text field to the front, and even send the detail
text label to the back. I know that all that is done correctly,
because on exit from -tableView: willDisplayCell:
forRowAtIndexPath: the cell's content view's subviews array is:
cell.contentView.subviews on exit from willDisplayCell:
(
<UILabel: 0xd36770; frame = (11 24; 135 18); text = 'Detail
Label Detail Label...'; clipsToBounds = YES; userInteractionEnabled
= NO; layer = <CALayer: 0xd36160>>,
<UILabel: 0xd35de0; frame = (11 2; 135 22); text = 'Text Label
Text Label Tex...'; clipsToBounds = YES; userInteractionEnabled =
NO; layer = <CALayer: 0xd360b0>>,
<UITextField: 0xd30220; frame = (155 10; 135 23); text = 'Text
Field Text Field Tex...'; clipsToBounds = YES; opaque = NO;
autoresize = LM; tag = 1; layer = <CALayer: 0xd30680>>
)
Note how all the frame rectangles are correctly set and note also
that the text field is above both labels, in the subview order.
Yet, the cell displays as in the picture: both labels have the
correct size but display as if they extended across the entire
content view. Moreover, the detail text label refuses to be
displayed in the back, even though it *is* in the back by the time
the willDisplayCell method exits.
Given how common something like this must be (reusing standard
cells, with frame changes) and how fundamentally important the view
hierarchy is, I'm inclined to think that the behavior I'm seeing
isn't a bug but, rather, the result of something trivial that I'm
missing. Yet, I can't see anything wrong with my code, so I'd
appreciate if someone looked at the sample project I created, which
can be downloaded from
http://www.restlessbrain.com/cocoadev/UITableView_cell_display_bug.zip
To summarize, there are 3 strange behaviors that I'm seeing:
a. the subview order for the subviews of the cell's content view
changes between exiting -tableView: cellForRowAtIndexPath: and
entering -tableView: willDisplayCell: forRowAtIndexPath:
b. the label frame rectangles are resized but the labels display as
if the frames had not been changed.
c. setting a specific subview order has no effect on how the labels
are displayed.
If I'm not missing anything obvious, I'll file a bug report.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden