Re: UILabel's sizeToFit - only on re-used cells
Re: UILabel's sizeToFit - only on re-used cells
- Subject: Re: UILabel's sizeToFit - only on re-used cells
- From: Quincey Morris <email@hidden>
- Date: Tue, 14 Jan 2014 11:44:46 -0800
On Jan 14, 2014, at 11:20 , Torsten Curdt <email@hidden> wrote:
> MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
>
> I then setup the cell
>
> cell.myLabel.text = @"test";
> cell.myLabel.textColor = [UIColor blackColor];
>
> and resize the label to use the proper space for the content
>
> [cell.myLabel sizeToFit];
The size of the cell you get from dequeueReusableCellWithIdentifier is meaningless until the cell gets added to the table view, which doesn’t happen until you return the cell from the delegate method you’re in.
One solution is to manually resize the cell (you probably care only about the width?) before returning it. Another is to resize the label later, after the cell is added to the table. (IIRC, the delegate method ‘tableView:willDisplayCell:forRowAtIndexPath:; was where I did it.) Yet another is to use auto layout to resize the label.
_______________________________________________
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