Re: [iPhone] UITableView cell display bugs ?

2009-07-21 Thread WT

On Jul 20, 2009, at 5:03 PM, David Duncan wrote:


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.


In order to do what you want you must subclass UITableViewCell and  
override layoutSubviews to do your layout. What is happening is your  
adding and moving around views before this layout has occurred, and  
then the default layout mechanism is resetting them. Your  
layoutSubviews override should call [super layoutSubviews] first.


Aha! So that's the trivial part I was missing. Thank you, David.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


[iPhone] UITableView cell display bugs ?

2009-07-20 Thread WT

Hello,

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.

Thanks in advance.

inline: Picture 1.png



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: [iPhone] UITableView cell display bugs ?

2009-07-20 Thread Steve Christensen
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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: [iPhone] UITableView cell display bugs ?

2009-07-20 Thread Johan Claesson
Once upon a time Steve Christensen wrote:
  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.


I agree and recommend the following free Screencast from Pragmatic:
http://pragmaticstudio.com/screencasts/5-custom-table-cells-in-interface-builder
IB is the way to go, doing this via code is troublesome.


BR /Johan

PS. Sorry Steve, accidentally sent to you instead to the list. DS.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: [iPhone] UITableView cell display bugs ?

2009-07-20 Thread David Duncan

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.


In order to do what you want you must subclass UITableViewCell and  
override layoutSubviews to do your layout. What is happening is your  
adding and moving around views before this layout has occurred, and  
then the default layout mechanism is resetting them. Your  
layoutSubviews override should call [super layoutSubviews] first.


--
David Duncan
Apple DTS Animation and Printing

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com