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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:42:47+00:00 2026-05-22T20:42:47+00:00

Got pretty far with this one but am hanging on the part where I

  • 0

Got pretty far with this one but am hanging on the part where I read out the string information.

I made a cell that receives data from an external xml file, it all works fine but some cell contain to much text which I want to display over multiple lines. Also no problem. But the tricky part is the dynamic height of my cell. I configured this in the heightForRowAtIndexPath: method, but I need to know the amount of text(rows) the cell contains, and I am stuck on the part how to connect that to my cellText(string) variable.
Any help would be welcome 🙂

Here is my code:

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

    // Set the text in the cell for the section/row.
    NSString *endDate = [XMLParser stringFromDate:[XMLParser dateFromString:stage.end]];
    int endDateLength = endDate.length;
    NSString *endTime = [NSString stringWithFormat:@"%@", [endDate substringFromIndex:endDateLength -7]];

    NSString *startDate = [XMLParser stringFromDate:[XMLParser dateFromString:stage.start]];
    int startDateLength = startDate.length;
    NSString *startTime = [NSString stringWithFormat:@"%@", [startDate substringFromIndex:startDateLength -7]];

    NSString *date = [XMLParser stringFromDate:[XMLParser dateFromString:stage.start]];
    int dateLength = date.length;
    NSString *dateString = [NSString stringWithFormat:@"%@", [date substringToIndex:dateLength -7]];

    NSString *cellText = nil;
    NSString *cellExplainText = nil;

    //Pre title arrays
    dateTitleArray      = [[NSArray alloc] initWithObjects:@"Dag", @"Start tijd", @"Eind tijd", nil];
    nameTitleArray      = [[NSArray alloc] initWithObjects:@"Naam", @"Graad",nil];
    addressTitleArray   = [[NSArray alloc] initWithObjects:@"Dojo", @"Straat", @"Plaats",nil];
    infoTitleArray      = [[NSArray alloc] initWithObjects:@"Kosten", @"Contact", @"Details", nil];

    dateArray           = [[NSArray alloc] initWithObjects: dateString, startTime, endTime, nil];
    nameArray           = [[NSArray alloc] initWithObjects: stage.teacher, stage.grade, nil];
    addressArray        = [[NSArray alloc] initWithObjects: stage.dojo, stage.street, stage.city, nil];
    infoArray           = [[NSArray alloc] initWithObjects: stage.cost, stage.contact, stage.details, nil];

    switch (indexPath.section)
    {
        case 0:
            cellExplainText = [dateTitleArray objectAtIndex:indexPath.row];
            cellText        = [dateArray objectAtIndex:indexPath.row];
            break;
        case 1:
            cellExplainText = [nameTitleArray objectAtIndex:indexPath.row];
            cellText        = [nameArray objectAtIndex:indexPath.row];
            break;
        case 2:
            cellExplainText = [addressTitleArray objectAtIndex:indexPath.row];
            cellText        = [addressArray objectAtIndex:indexPath.row];
            break;
        case 3:
            cellExplainText = [infoTitleArray objectAtIndex:indexPath.row];
            cellText        = [infoArray objectAtIndex:indexPath.row];
            break;
        default:
            break;
    }

    [dateTitleArray release];
    [nameTitleArray release];
    [addressTitleArray release];
    [infoTitleArray release];

    [dateArray release];
    [nameArray release];
    [addressArray release];
    [infoArray release];

    cell.textLabel.text = cellExplainText;
    cell.detailTextLabel.text = cellText;
    cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.detailTextLabel.numberOfLines = 0;
    cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellTextSize = ????????????;
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellTextSize sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 12;
}
  • 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-22T20:42:48+00:00Added an answer on May 22, 2026 at 8:42 pm
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGSize maxSize = CGSizeMake(urMaxSize);
    CGSize cellSize = [itemName sizeWithFont:[UIFont systemFontOfSize:15]
             constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
    return cellSize.height;
    }
    

    itemName is the text u want to fill it with. I guess it is [infoTitleArray objectAtIndex:indexPath.row] and corresponding array information based on index. You can get the section also in this method so you can get the string.

    If you want to use your method

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NSString *cellText;
    switch (indexPath.section)
        {
            case 0:
                cellText = [dateTitleArray objectAtIndex:indexPath.row];
    
                break;
            case 1:
                cellText = [nameTitleArray objectAtIndex:indexPath.row];
    
                break;
            case 2:
                cellText = [addressTitleArray objectAtIndex:indexPath.row];
    
                break;
            case 3:
                cellText = [infoTitleArray objectAtIndex:indexPath.row];
    
                break;
            default:
                break;
        }
    
        UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0];
        CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
        CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
    
        return labelSize.height + 12;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted earlier today about template classes, but was pretty far off and got
We've got a reasonable sized C++ application that's pretty old at this stage, so
this is probably not that hard to do. But I've got two text files.
I'm working on an MFC application, that got pretty messy over years and over
I got some pretty messy urls that i got via scraping here, problem is
I've got a pretty minor problem that I think can be resolved by re-thinking
I am building a Django application that is a pretty basic blog, so far
My question is seemingly simple but has been pretty elusive. I want one value
I've got a mental block. I'm pretty certain this is a dead simple noob
I've got a pretty simple problem, but I've become clueless on what is causing

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.