Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:18:10+00:00 2026-06-14T19:18:10+00:00

I’m very much new to iphone development and strucked at a point. Actually my

  • 0

I’m very much new to iphone development and strucked at a point. Actually my need is I’m displaying some results in a UITableView and I’m displaying then UILables of UITableView's cell..
How can I make the UILabel's to adjust the content according to the text. Actually text is not static .It may be changing at run time.So I need to set dynamic size to a UILabel .Ans secondly suppose if the text is null then it should not show any space and immediately the next UILabel should start .How can I make it possible ?
Here is my code..

self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,150,320,800) style:UITableViewStylePlain];
            self.tableView.delegate=self;
            self.tableView.dataSource=self;
            self.tableView.scrollEnabled = NO;
            [self.view addSubview:self.tableView];

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(currentHtmlElement==@"3")
    {
        static NSString *CellIdentifier=@"Cell";

        UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:CellIdentifier]autorelease];
        }
        NSMutableDictionary *d = (NSMutableDictionary *) [arr2 objectAtIndex:indexPath.row];
        cell.accessoryType= UITableViewCellAccessoryDetailDisclosureButton;
       UILabel  *name1= [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 320, 40)];
        name1.font=[UIFont boldSystemFontOfSize:16];
        [name1 setTextAlignment:UITextAlignmentLeft];
        [name1 setText:[d valueForKey:@"Name"]];
        name1.tag = 111;
        [cell addSubview:name1];
        [name1 release];

        UILabel *codetype=[[UILabel alloc]initWithFrame:CGRectMake(10, 45, 320,15)];
        codetype .font=[UIFont boldSystemFontOfSize:12];        
        [codetype setTextAlignment:UITextAlignmentLeft];
        [codetype  setText:[d valueForKey:@"Code"]];
        codetype.tag=112;
        [cell addSubview:codetype];
        [codetype  release];    

        UILabel *id=[[UILabel alloc]initWithFrame:CGRectMake(10, 68, 320,10)];
        id .font=[UIFont fontWithName:@"arial" size:12];        
        [id setTextAlignment:UITextAlignmentLeft];
        [id  setText:[d valueForKey:@"ID"]];
        id.tag=113;
        [cell id ];
        [id  release]; 

        UILabel *address=[[UILabel alloc]initWithFrame:CGRectMake(10, 85, 320,10)];
        address .font=[UIFont fontWithName:@"arial" size:12];        
        [address setTextAlignment:UITextAlignmentLeft];
        [address  setText:[d valueForKey:@"address"]];
        line2.tag=114;
        [cell addSubview: address];
        [address  release]; 

        UILabel *city = [[UILabel alloc]initWithFrame:CGRectMake(10, 105, 320, 10)];
        city .font=[UIFont fontWithName:@"arial" size:12];        
        [city  setTextAlignment:UITextAlignmentLeft];
        [city  setText:[d valueForKey:@"City"]];
        city.tag=115;
        [cell addSubview:city ];
        [city  release];
}

Here I have set all the UILabels to static size.But what I need is dynamic size.and suppose if the address label is null then it should not show any space and next label i.e city should start immediately next after id ..How is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:18:11+00:00Added an answer on June 14, 2026 at 7:18 pm

    I did this task in my code…. you can use this code and do changes according to your code….and let me know if you get any problem.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
    {
        NSMutableDictionary *dicNotification =[[NSMutableDictionary alloc]initWithDictionary: [myNotification objectAtIndex:indexPath.row]];
    
        //code to get notification text height
        NSString *text = [dicNotification  objectForKey:@"message"];
        CGSize constraint = CGSizeMake(175, 100.0f);
        CGSize size = [text sizeWithFont: [UIFont fontWithName:@"Verdana" size:12] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
        return size.height;
    }
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) 
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    
            //label for message
            UILabel *lblMsg = [[UILabel alloc] initWithFrame:CGRectZero];
            lblMsg.tag = 12;
            lblMsg.backgroundColor = [UIColor clearColor];
            [lblMsg setFont:[UIFont fontWithName:@"Verdana" size:12]];
            [lblMsg setLineBreakMode:UILineBreakModeWordWrap];
    
            [cell addSubview:lblMsg];
        }
    
        NSMutableDictionary *dicNotification =[[NSMutableDictionary alloc]initWithDictionary: [myNotification objectAtIndex:indexPath.row]];
    
        //get the message height set frame height to imageView(BubbleMid & Top) & labelMSG
        NSString *txt = [dicNotification  objectForKey:@"message"];
        CGSize constraint = CGSizeMake(175, 2000.0f);
        CGSize size = [txt sizeWithFont: [UIFont fontWithName:@"Verdana" size:12] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    
        //set frame height to labelMsg
        UILabel *lblMsg = (UILabel *)[cell viewWithTag:12];
        lblMsg.frame = CGRectMake(15,25, 175, size.height);
        [lblMsg setNumberOfLines:size.height/16];
    
        //set labelMsg text
        lblMsg.text = [dicNotification  objectForKey:@"message"];
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.