Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically Loading Tableview Header with Calculated size
    primarykey
    data
    text
    <p>Hi all I am developing an app.I want to show a table view with a header view.When i navigate from Root view to Next view(tableview) which is as shown below.But my question is when i passes some text from root view to Next view(table view) as a header to next view it shows like the following in appropriate format.i need solution for this to show some better format.Following code that i used for this.<img src="https://i.stack.imgur.com/iknNj.png" alt="enter image description here"></p> <pre><code>- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { /* NSString *str_header1; str_header1=[[NSString alloc]initWithString:@"Heading : "]; str_header1=[str_header1 stringByAppendingFormat:str_code1]; str_header1=[str_header1 stringByAppendingFormat:@" - "]; str_header1=[str_header1 stringByAppendingFormat:str_header]; */ // Create label with section title UILabel *tmpTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 300, 20)]; UILabel *titleLabel = tmpTitleLabel; titleLabel.font = [UIFont boldSystemFontOfSize:12]; titleLabel.numberOfLines = 0; titleLabel.textColor = [UIColor colorWithRed:0.30 green:0.34 blue:0.42 alpha:1.0]; titleLabel.shadowColor = [UIColor whiteColor]; titleLabel.shadowOffset = CGSizeMake(0.0, 1.0); titleLabel.backgroundColor=[UIColor clearColor]; titleLabel.lineBreakMode = UILineBreakModeWordWrap; titleLabel.text = str_combine; //Calculate the expected size based on the font and linebreak mode of label CGSize maximumLabelSize = CGSizeMake(300,9999); expectedLabelSize= [str_combine sizeWithFont:titleLabel.font constrainedToSize:maximumLabelSize lineBreakMode:titleLabel.lineBreakMode]; //Adjust the label the the new height CGRect newFrame = titleLabel.frame; newFrame.size.height = expectedLabelSize.height; titleLabel.frame = newFrame; // Create header view and add label as a subview UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 320, expectedLabelSize.height+30)]; [view addSubview:titleLabel]; return view; </code></pre> <p>}</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection: (NSInteger)section { return expectedLabelSize.height+30; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload