The way is handled something similar is by first calculating the label size for
the dynamic string (which you probably need anyway), then using the returned
value in the heightForHeaderInSection (or recalculating it with a method call),
followed by calling reloadData on the tableView. The code below, by the way, is
portrait only, which is fine in my case, but unlikely to work in yours, so
you'd have to change that.
somewhere in your data model code:
float labelSizeHeight = [self calculateLabelSizeHeightForText:@"blablabla"];
-(float)calculateLabelSizeHeightForText:(NSString *)text {
CGSize constraintSize = ([[UIDevice currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPad) ? CGSizeMake(748.0f, MAXFLOAT) : CGSizeMake(300.0f,
MAXFLOAT);
//You will need to define kDefaultCellFont
CGSize labelSize = [text sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:constraintSize
lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height+10;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section {
return labelSizeHeight;
}
Op Aug 6, 2013, om 9:23 AM heeft Rick Mann <[email protected]> het volgende
geschreven:
> Unfortunately, that won't compute the height of the
> UITableViewHeaderFooterView, which has two different labels with different
> text characteristics, and who know what positioning within.
>
> On Aug 5, 2013, at 18:57 , synelang <[email protected]> wrote:
>
>> Try this : (never tested)
>>
>> • void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView
>> *)view forSection:(NSInteger)section_
>> {
>> CGSize size = [dataString sizeWithFont:font constrainedToSize:size
>> lineBreakMode:UILineBreakModeWordWrap];
>> CGFrame frame = view.frame;
>> frame.size.height = size.height;
>> • [view setFrame:frame];
>> • }
>>
>>
>>
>> Original Message
>> Sender: Rick Mann<[email protected]>
>> Recipient: Cocoa Dev List<[email protected]>
>> Date: 星期二, 8月 6, 2013 09:25
>> Subject: Computing the height for a UITableViewHeaderFooterView
>>
>> Is there any way around manually providing the height for a table header
>> view? If I simply provide a title string for the header, UITableView is able
>> to compute the height itself. But if I use a UITableViewHeaderFooterView and
>> set the textLabel and detailTextLabel, I also have to set the height (as far
>> as I can tell).
>>
>> But the text I'm rendering is dynamic, and could change the number of lines
>> used. Not sure how best to handle this.
>>
>> --
>> Rick
>>
>>
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (
>> [email protected]
>> )
>>
>> 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:
>>
>> https://lists.apple.com/mailman/options/cocoa-dev/synelang%40gmail.com
>>
>>
>> This email sent to
>> [email protected]
>
>
> --
> Rick
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/diederik%40tenhorses.com
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]