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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:44:10+00:00 2026-05-23T06:44:10+00:00

A tableView cell of UITableViewCellStyleSubtitle will truncate text. Also, a regular UITableCell of multiple

  • 0

A tableView cell of UITableViewCellStyleSubtitle will truncate text.
Also, a regular UITableCell of multiple lines will truncate text if the delete slide is used.

However, my UITableViewCellStyleSubtitle cell of mulitple lines doesn’t truncate the text when delete slide comes in. Instead, it stretches outside the boundaries of the cell. Can I fix this? Here is some of my code …

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"];

if (cell==nil){
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellType"] autorelease];
    // set the labels to the appropriate text for this row
    cell.textLabel.text = [(Group*)[composeData objectInChosenGroupsListAtIndex:indexPath.row]groupName];
    cell.textLabel.lineBreakMode=UILineBreakModeTailTruncation;
    cell.textLabel.numberOfLines = 0;

    if ([(Group*)[composeData objectInChosenGroupsListAtIndex:indexPath.row]isDynamic]){
         cell.detailTextLabel.text = NSLocalizedString(@"dynamic", @"dynamic");
    }
    else {
        //get and set the group size
        int groupSize = [(Group*)[composeData objectInChosenGroupsListAtIndex:indexPath.row]groupSize];

        if (groupSize == 1)
            cell.detailTextLabel.text = NSLocalizedString(@"1Contact", @"1 contact");
        else
            cell.detailTextLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%dContacts", @"%d contacts"), groupSize];
    }     
}

return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = (UITableViewCell *)[self tableView: tableView cellForRowAtIndexPath: indexPath];

CGRect frame = [UIScreen mainScreen].bounds;
CGFloat width = frame.size.width;

int section = indexPath.section;

NSString *title_string = cell.textLabel.text;
NSString *detail_string = cell.detailTextLabel.text;

CGSize title_size = {0, 0};
CGSize detail_size = {0, 0};

if (title_string && [title_string isEqualToString:@""] == NO ) {
    title_size = [title_string sizeWithFont:[UIFont systemFontOfSize:22.0]
                          constrainedToSize:CGSizeMake(width, 4000)
                              lineBreakMode:cell.textLabel.lineBreakMode];
}

if (detail_string && [title_string isEqualToString:@""] == NO ) {
    detail_size = [detail_string sizeWithFont:[UIFont systemFontOfSize:18.0]
                            constrainedToSize:CGSizeMake(width, 4000)
                                lineBreakMode:cell.detailTextLabel.lineBreakMode];
}

CGFloat title_height = title_size.height;
CGFloat detail_height = detail_size.height;

CGFloat content_size = title_height + detail_height;

CGFloat height;

switch ( section ) {

    case 0:
        height = content_size;
        break;

        //Just in case  
    default:
        height = 44.0;
        break;

}

return height;

}
  • 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-05-23T06:44:11+00:00Added an answer on May 23, 2026 at 6:44 am

    This was so tough to work out! The problem is that it will always stretch the text if numberOfLines is set to 0. Therefore, I needed to calculate the numberOfLines, and set it for each cell.

    cell.textLabel.numberOfLines = textLabelheight/textLabelFontSize;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tableview cell in a view which has some text in it,the
I'm using the following code to size a UITableViewCellStyleSubtitle cell to fit text that
i want to add a UIPageControl to a single tableView Cell. It should be
I'm loading a view from a tableview touched cell that contains a photo that
I was calling UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; from -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath in
This - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.accessoryType
The debugger threw me this error UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; in this method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; but I
When I select a cell in section 0 of my tableview I always get
I would like to select a cell in a tableview, except with code before

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.