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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:19:46+00:00 2026-05-27T13:19:46+00:00

I am facing some problem in reloading the table. My cellForRowAtIndexPath is: – (UITableViewCell

  • 0

I am facing some problem in reloading the table. My cellForRowAtIndexPath is:

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

    int counter=indexPath.row;

    NSString *CellIdentifier = [NSString stringWithFormat:@"%d",counter];

    // Dequeue or create a cell of the appropriate type.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        cell.selectionStyle=UITableViewCellSelectionStyleNone;


    //ID
    UILabel *lblID=[[UILabel alloc]init];
    lblID.frame=CGRectMake(10, 15.0, 150, 30.0);
    [lblID setFont:[UIFont boldSystemFontOfSize:20.0]];
    [lblID setBackgroundColor:[UIColor clearColor]];
    [lblID setTextColor:[UIColor blackColor]];
    lblID.text = [arrID objectAtIndex:indexPath.row];
    [cell.contentView addSubview:lblID];
    [lblID release];

    //Date
    UILabel *lblName=[[UILabel alloc]init];
    lblName.frame=CGRectMake(130, 15.0, 250, 30.0);
    [lblName setFont:[UIFont systemFontOfSize:20.0]];
    [lblName setBackgroundColor:[UIColor clearColor]];
    [lblName setTextColor:[UIColor blackColor]];
    lblName.text = [arrProductName objectAtIndex:indexPath.row];
    [cell.contentView addSubview:lblName];
    [lblName release];

    //Qty
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(320, 20, 50, 30)];
    [textField addTarget:self action:@selector(TextOfTextField:)
        forControlEvents:UIControlEventEditingDidEnd];
    textField.userInteractionEnabled = true;
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15];
    textField.text = [arrItems objectAtIndex:indexPath.row];
    textField.tag = indexPath.row;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.keyboardType = UIKeyboardTypePhonePad;
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
    textField.delegate = self;
    [arrTxtItems addObject:textField];
    [cell.contentView addSubview:textField];
    [textField release];

    //Discount
    UITextField *txtDiscount = [[UITextField alloc] initWithFrame:CGRectMake(460, 20, 50, 30)];
  //  [txtDiscount addTarget:self action:@selector(TextOfTextField:)
    //    forControlEvents:UIControlEventEditingDidEnd];
    txtDiscount.userInteractionEnabled = true;
    txtDiscount.borderStyle = UITextBorderStyleRoundedRect;
    txtDiscount.font = [UIFont systemFontOfSize:15];
    txtDiscount.text = [arrDiscount objectAtIndex:indexPath.row];
    txtDiscount.tag = indexPath.row;
    txtDiscount.autocorrectionType = UITextAutocorrectionTypeNo;
    txtDiscount.keyboardType = UIKeyboardTypePhonePad;
    txtDiscount.returnKeyType = UIReturnKeyDone;
    txtDiscount.clearButtonMode = UITextFieldViewModeWhileEditing;
    txtDiscount.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
    txtDiscount.delegate = self;
    [arrTxtDiscount addObject:txtDiscount];
    [cell.contentView addSubview:txtDiscount];
    [txtDiscount release];

    //Price
    UILabel *lblPrice=[[UILabel alloc]init];
    lblPrice.frame=CGRectMake(560, 15.0, 250, 30.0);
    [lblPrice setFont:[UIFont boldSystemFontOfSize:20.0]];
    [lblPrice setBackgroundColor:[UIColor clearColor]];
    [lblPrice setTextColor:[UIColor blackColor]];
    [arrLblNetPrice addObject:lblPrice];
    NSString *strPrice = [arrPrice objectAtIndex:indexPath.row];

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
    [formatter setGroupingSeparator:@"."];
    [formatter setGroupingSize:2];
    [formatter setUsesGroupingSeparator:YES];
    [formatter setSecondaryGroupingSize:3];
    NSString *str = [formatter stringFromNumber:[NSNumber numberWithDouble:[strPrice doubleValue]]];
    [formatter release];
    NSLog(@"str :   %@",str);
    NSLog(@"strPrice :    %@",strPrice);
    lblPrice.text = str;
    [cell.contentView addSubview:lblPrice];
    [lblPrice release];
    }
        return cell;
}  

Structuring the cell this way helps me preserve the values of textFields when I scroll the table. But at some point when I reload the table control does not fall in the if condition because the cell has not been released yet. Where should I release the cell in this condition?

  • 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-27T13:19:47+00:00Added an answer on May 27, 2026 at 1:19 pm

    You need to separate creating/acquiring the cell instance from configuring the cell properties with data. Change your code as follows:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        int counter=indexPath.row;
    
        NSString *CellIdentifier = [NSString stringWithFormat:@"%d",counter];
    
        // Dequeue or create a cell of the appropriate type.
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
            //ID
            UILabel *lblID=[[UILabel alloc]init];
            lblID.frame=CGRectMake(10, 15.0, 150, 30.0);
            [lblID setFont:[UIFont boldSystemFontOfSize:20.0]];
            [lblID setBackgroundColor:[UIColor clearColor]];
            [lblID setTextColor:[UIColor blackColor]];
            lblID.tag = MyViewTagIDLabel;      // make an enum to give your subviews unique tags > 0
            [cell.contentView addSubview:lblID];
            [lblID release];
    
            // add the rest of your subviews
    
            // any other cell configuration that does not change based on the ind
        }
    
        // configure the cell with data based on the indexPath
        UILabel lblID = [cell.contentView viewWithTag:MyViewTagIDLabel];
        lblID.text = [arrID objectAtIndex:indexPath.row];
    
        // configure the rest of the subviews
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing some problem in iPhone application development for Reading PDF. I have
I am facing some problem in generating oauth_signature for flickr api. Can you please
I am facing some problem with MySQL database. actually It was fast when I
I am getting a value through Query string but facing some problem in printing
Scenario: I have configured SQOOP on my PC. But I am facing some problem
I am facing some problem with use of operator == in the following c++
i am facing some problem with files with huge data. i need to skip
Yii beginner here. I am facing some problem with how to query the database
I'm facing some known solvable problem but struck out here. In my code, the
I am facing some problem with ListView , I have inflated a layout with

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.