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 8957109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:54:43+00:00 2026-06-15T14:54:43+00:00

I need to create a UITableView in which UITableViewCell contains two UILabel, one of

  • 0

I need to create a UITableView in which UITableViewCell contains two UILabel, one of them should fit height to its content NSString. The width of the UILabel is fixed, and the number of lines is set to 0. How can I get the height ?
I see code like this:

CGSize maximumSize = CGSizeMake(300, 9999);
NSString *myString = @"This is a long string which wraps";
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:14];
CGSize myStringSize = [myString sizeWithFont:myFont 
                           constrainedToSize:maximumSize 
lineBreakMode:self.myLabel.lineBreakMode];

but the result is: there is only one character in a line of UILabel.
Why cannot I use this method? Thank you very much!

  • 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-15T14:54:44+00:00Added an answer on June 15, 2026 at 2:54 pm

    I finally get it working, code in my project:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"shopmessage";
    UITableViewCell *cell;
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    UILabel* content = (UILabel*)[cell viewWithTag:11];
    UILabel* date = (UILabel*)[cell viewWithTag:12];
    NSDictionary* msg = [ _msglist objectAtIndex:indexPath.row];
    NSString* type = [[msg objectForKey:@"msgtype"] intValue] == 0 ? @"我:":@"店家:";
    [content setText:[NSString stringWithFormat:@"%@%@",type,[msg objectForKey:@"sendmsg"]]];
    [date setText:[msg objectForKey:@"sendtime"]];
    
    CGSize contentsize = [content.text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(280, 1000) lineBreakMode:UILineBreakModeWordWrap];
    //    content.frame.size = contentsize;
    content.frame = CGRectMake(content.frame.origin.x, content.frame.origin.y, contentsize.width, contentsize.height);
    
    [date setText:[msg objectForKey:@"sendtime"]];
    //    date.frame.origin = CGPointMake(date.frame.origin.x, content.frame.origin.y + content.frame.size.height + 10);
    date.frame = CGRectMake(date.frame.origin.x, content.frame.origin.y + content.frame.size.height, date.frame.size.width, date.frame.size.height);
    return cell;
    

    }

    - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSDictionary* msg = [ _msglist objectAtIndex:indexPath.row];
        NSString* text =[msg objectForKey:@"sendmsg"];
        CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(280, 1000) lineBreakMode:UILineBreakModeCharacterWrap];
    
        return size.height + 30;
    }
    

    reference:Apple Support Communities

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to create a custom DNS name server using C which will check against
I need to create a WP site which will have multiple subjects. Each subject
I need to create a class with two properties: LogOutput ExceptionOutput These properties (Actions<>)
I want to create uitableview like the following , also I need to add
I have a UITableView which loads its data from the web. It takes a
I need to create a small UITableView with cells that each contain a UISwitch
In my iphone app, I need to create a controller for which the view
I have a UITableView which I need to update about 2-3 times a second
I'm trying to create an app which will need to search the web by
I need create custom dialog and put JPanel into it. Is it possible?

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.