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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:06+00:00 2026-05-28T02:11:06+00:00

I am loading a tableview. Each cell of my tableview should have varying heights

  • 0

I am loading a tableview. Each cell of my tableview should have varying heights depending on the data. In the code below, I am displaying contacts in each row of the table. Each contacts may have multiple phone numbers. I am displaying the contacts with their phone numbers in each cells. So depending on the number of phone numbers of each contact, the height of the cell will change. I have written the following code to display the contacts in the table.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{
NSArray *contactsInSection = [sectionsArray objectAtIndex:indexPath.section];
ContactsHelper *contact = [contactsInSection objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    UIButton *checkBox = [[UIButton alloc] init];
    checkBox.tag = contact.contactID;
    [cell.contentView addSubview:checkBox];
    [checkBox setFrame:CGRectMake(6,14,20,20)];
    [checkBox release];

    UILabel *CellTextlabel = [[UILabel alloc] init];
    CellTextlabel.tag = 222;
    [CellTextlabel setFrame:CGRectMake(40, 5, 200, 20)];
    [cell.contentView addSubview:CellTextlabel];
    [CellTextlabel release];

    UILabel *detailcellTextlabel = [[UILabel alloc] init];
    detailcellTextlabel.tag = 333;
    [detailcellTextlabel setFrame:CGRectMake(40, 24, 200, 20)];
    detailcellTextlabel.font = [UIFont boldSystemFontOfSize:12];
    detailcellTextlabel.textColor = [UIColor grayColor];

    [[cell contentView] addSubview:detailcellTextlabel];
    [detailcellTextlabel release];
}
ABAddressBookRef addressbook = ABAddressBookCreate();
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressbook,contact.contactID);
UIButton *checkBox = (UIButton *)[cell.contentView viewWithTag:contact.contactID];

if(isActivDeactivButton)
{
    [checkBox setImage:[UIImage imageNamed:@"disabled_checkbox.png"] forState:UIControlStateNormal]; 
   }
else{
   [checkBox setImage:[UIImage imageNamed:@"selected_checkbox.png"] forState:UIControlStateNormal];
 }

[checkBox addTarget:self action:@selector(checkBoxSelected:) forControlEvents: UIControlEventTouchUpInside];

UILabel *editCellTextlabel = (UILabel *)[cell.contentView viewWithTag:222];
editCellTextlabel.font = [UIFont boldSystemFontOfSize:18];

UILabel *detailcellTextlabel = (UILabel *)[cell.contentView viewWithTag:333];


if (sendSMS) {
    NSMutableArray *phoneNumberEntries = [[[NSMutableArray alloc] init] autorelease];
        editCellTextlabel.text = contact.lastName;
    ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
    numberOfLines = ABMultiValueGetCount(phoneNumbers);


    for (int i = 0; i < ABMultiValueGetCount(phoneNumbers)  ; i++) {
        CFStringRef phoneNoEntries = ABMultiValueCopyValueAtIndex(phoneNumbers, i);
        NSString *phoneNumber = (NSString *) phoneNoEntries;
        [phoneNumberEntries addObject:phoneNumber];  

     //   NSLog(@"email id %@", detailcellTextlabel.text);
        CFRelease(phoneNoEntries);
    }
     detailcellTextlabel.numberOfLines = ABMultiValueGetCount(phoneNumbers);
   [detailcellTextlabel setFrame:CGRectMake(40, 24, 200, 20 + 20 * [phoneNumberEntries count])];
   detailcellTextlabel.lineBreakMode = UILineBreakModeWordWrap;
    detailcellTextlabel.lineBreakMode = UILineBreakModeWordWrap;
    detailcellTextlabel.numberOfLines = numberOfLines;
    detailcellTextlabel.text = [phoneNumberEntries componentsJoinedByString:@"\n"];

   // NSLog(@"email id %@", detailcellTextlabel.text);
    CFRelease(phoneNumbers);

}
CFRelease(addressbook);
return cell;
}

I cant find a way to set the height of the cells correctly. I have implemented

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

delegate method and tried various logics. But I am not able to set the height of the row correctly. One problem seems to be indexpath.section values, which tends to change in both delegate methods. Need help in this case.

  • 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-28T02:11:06+00:00Added an answer on May 28, 2026 at 2:11 am

    You can use: – (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    And set the row height according to the section/row of the cell.

    For example:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     switch(indexPath.row){
       case:0
        return 100;
       break;
    
       case:1
        return 200;
       break;
      }
    }
    

    etc….

    If you have more then 1 section try this

         - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{   
    
          switch(indexPath.section){
            case:0
                switch(indexPath.row){
                    case:0
                        return 100;
                        break;
    
                    case:1
                        return 200;
                        break;
                }
                break;
    
            case:1
                switch(indexPath.row){
                    case:0
                        return 100;
                        break;
    
                    case:1
                        return 200;
                        break;
                }
    
                break;
        }
    }
    

    Shani

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

Sidebar

Related Questions

I have a TableView loading a custom cell and loading the data from a
I'm loading a view from a tableview touched cell that contains a photo that
I have around 20 tableview cells that each contain a number (2-5) thumbnail sized
So I have a tableView with navigation controller. And the data loads from url.
I have this code: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic NSLog(@didSelectRowAtIndexPath);
I have a UITableView with custom UITableViewCells. Each cell asynchronously loads an image and
I am loading a tableView with 500 rows. The problem is that in each
In My TableVIew Im loading Custome cell With Xib, For Every Entry Of CellForIndexPath,Cell
I have the following code in my search method that updates the tableview. for
I have an tabBarController app with 2 tabBarItems. each viewControllers contains tableView. On didSelectRowAtIndexPath

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.