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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:11:42+00:00 2026-06-18T22:11:42+00:00

I have created a UITableViewCell nib that I am loading into my tableview, however

  • 0

I have created a UITableViewCell nib that I am loading into my tableview, however something weird is happening when I scroll through the table, if I am scrolling down the new cell that comes in shows the default values for a split second and then if I scroll up the same thing is happening at the top.

The code below is deciding which nib to load depending on the data avalible from myObj, hopefully this is understandable

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (indexPath.section == 0) {
        // Set cell height
        [self tableView:tableView heightForRowAtIndexPath:indexPath];

        //call obj array with all of the values from my sorting algorithum
        SearchResultItem *myObj = (searchResultItem*)[dataArrayOfObjects objectAtIndex:indexPath.row];



        // This gets the year string ready  ----->

        // Create Year string
        NSString *yearRangeString = [[NSString alloc] init];

        // do some special stuff here with the years
        if ((myObj.yearStart < 1) && (myObj.yearFinish < 1)){
            //            yearRangeLabel.text = @"";
            yearRangeString = @"";
        }
        if ((myObj.yearStart < 1) && (myObj.yearFinish > 1)){
            //            yearRangeLabel.text = [NSString stringWithFormat:@"upto %i", myObj.yearFinish];
            yearRangeString = [NSString stringWithFormat:@"upto %i", myObj.yearFinish];
        }
        if ((myObj.yearStart > 1) && (myObj.yearFinish < 1)){
            //            yearRangeLabel.text = [NSString stringWithFormat:@"from %i", myObj.yearStart];
            yearRangeString = [NSString stringWithFormat:@"from %i", myObj.yearStart];
        }
        if ((myObj.yearStart > 1) && (myObj.yearFinish > 1)){
            //            yearRangeLabel.text = [NSString stringWithFormat:@"%i to %i",myObj.yearStart, myObj.yearFinish];
            yearRangeString = [NSString stringWithFormat:@"%i to %i",myObj.yearStart, myObj.yearFinish];
        }

        // adjust year string is (submodel) is avalible or not
        if (([yearSelectedString isEqualToString:@"all"]) && ([sModelSelectedString isEqualToString:@"all"])) {
            yearRangeString = [NSString stringWithFormat:@"(%@) %@", myObj.subModel, yearRangeString];
            yearRangeLabel.text = yearRangeString;
        }
        else if ((![yearSelectedString isEqualToString:@"all"]) && ([sModelSelectedString isEqualToString:@"aSearchResultItemll"])) {
            yearRangeString = [NSString stringWithFormat:@"(%@)", myObj.subModel];
            yearRangeLabel.text = yearRangeString;
        }
        else if (([yearSelectedString isEqualToString:@"all"]) && (![sModelSelectedString isEqualToString:@"all"])) {
            yearRangeString = [NSString stringWithFormat:@"%@", yearRangeString];
            yearRangeLabel.text = yearRangeString;
        }
        else if ((![yearSelectedString isEqualToString:@"all"]) && (![sModelSelectedString isEqualToString:@"all"])) {
            yearRangeLabel.text = nil;
        }

    // check year string if too large use B nibs ----->

        // Get yearRangeString width to see if you need to use a yearRangeLabel with second line
        CGSize yearStringSize = [yearRangeString sizeWithFont:[UIFont fontWithName:@"Helvetica" size:15] constrainedToSize:CGSizeMake(226, 21) lineBreakMode:NSLineBreakByWordWrapping ];

        // NSLog(@"width = %f, height = %f", yearStringSize.width, yearStringSize.height);



     // Get rest of nibs ready ----->

        // Set custom cell to display
        // check to see if there is a description, if there is choose the correct tableviewcell

        if (([myObj.note isEqualToString:@""]) && (([sModelSelectedString isEqualToString:@"all"]) || ([yearSelectedString isEqualToString:@"all"])) && (yearStringSize.width <= 100.00)) {

            // Configure the cell using custom cell
            [[NSBundle mainBundle] loadNibNamed:@"auSearchCell" owner:self options:nil];

            // Set up the different labels in each cell
            descriptionLabel.text = myObj.sDescription;
            iDLabel.text = [NSString stringWithFormat:@"%i", myObj.mID];
            cLabel.text = myObj.cDesc;
            INLabel.text = [NSString stringWithFormat:@"%i", myObj.ssID];

            cell = automativeSearchCell;
        }

        /// other if statments for different types of cells

         //Disclosure Indicator
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;
}

any help would be greatly appreciated

  • 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-18T22:11:43+00:00Added an answer on June 18, 2026 at 10:11 pm

    It looks like you have a couple of problems. You shouldn’t be calling heightForRowAtIndexPath:, it’s called by the table view. You should set up any heights you need there based on the index path. It also looks like your dequeuing a normal UITableViewCell every time, and then switching to your other cell if a string is too long. You should do the string size check first, and then dequeue the proper cell. Also, it looks like you’re loading the nib every t1me you have the too long string. Instead, you should just register your nib (in viewDidLoad perhaps) and then use the dequeueReusableCellWithIdentifier:forIndexPath: method instead of the older method you’re using. That method is always guaranteed to dequeue a cell, so there’s no need for the if cell == nil clause.

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

Sidebar

Related Questions

I have a UIStepper control that i created programmaticly in my UITableViewCell . I
I have a UITableView inside of a View created from a NIB. the table
I have successfully created a UITableView/UITableViewCell that is able to slide up and down
I have created sample application that insert 12 rows in tableview.And inserted fine.When after
I have an iPad app that is not showing a table created programmatically. Where
I have a UITableViewCell created in an external Nib from my storyboard. I have
I have created a customized call that is called in UITableViewCell (cellForRowAtIndexPath) . Everything
I have created a custom UITableViewCell that is added as a subview to my
This UITableViews gonna make me crazy! I have UITableViewCell created by - (UITableViewCell *)tableView:(UITableView
I have a nib-based table view cell which I created in Interface builder. I

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.