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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:16:03+00:00 2026-05-29T09:16:03+00:00

I have a global declared array and loading that array in table view but

  • 0

I have a global declared array and loading that array in table view but when i go to other controller and update that array and reload table view again then text in labels in table view cell is overriding. Newer update data is overriding and previous also displaying in same label. here is my code: Where item array is globally declared array.

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

static NSString *CellIdentifier = @"Cell";


UITableViewCell *cell = [self.tableview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
 reuseIdentifier:CellIdentifier] autorelease];    
  }

UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(45, 8, 100, 25)];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.font = [UIFont fontWithName:@"Arial" size:16];
nameLabel.text = [[itemsArray objectAtIndex:indexPath.row] objectForKey:@"itemname"];
[cell addSubview:nameLabel];
[nameLabel release];

UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.frame= CGRectMake(3, 3, 30, 30);
[deleteButton setImage: [UIImage imageNamed:@"cross_btn.png"] forState:UIControlStateNormal];
[cell addSubview:deleteButton];


UILabel *priceMark = [[UILabel alloc]initWithFrame:CGRectMake(150, 8, 65, 25)];
priceMark.backgroundColor = [UIColor clearColor];
priceMark.font = [UIFont fontWithName:@"Arial" size:14];
priceMark.text = [NSString stringWithFormat:@"Rs: %@",[[itemsArray objectAtIndex:indexPath.row] 
objectForKey:@"amount"]];
[cell addSubview:priceMark];     
[priceMark release];

UILabel *qtyLabel = [[UILabel alloc]initWithFrame:CGRectMake(225, 8, 60, 25)];
qtyLabel.backgroundColor = [UIColor clearColor];
qtyLabel.font = [UIFont fontWithName:@"Arial" size:14];
qtyLabel.text = [[itemsArray objectAtIndex:indexPath.row] objectForKey:@"qty"];
[cell addSubview:qtyLabel];
[qtyLabel release];

return cell;
} 

EDIT 2

now i am getting other problem when i update item array that is globally declared at 0 index and return back then it wont update the row in table view row at index 0 but when i update other rows then it updates. And also when i scroll table view towards upward then it shows value at index 0 on all index. here is my code

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
   reuseIdentifier:CellIdentifier] autorelease];    
    nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(45, 8, 100, 25)];
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.font = [UIFont fontWithName:@"Arial" size:16];
    [cell addSubview:nameLabel];

    deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    deleteButton.frame= CGRectMake(3, 3, 30, 30);
    [deleteButton setImage: [UIImage imageNamed:@"cross_btn.png"] forState:UIControlStateNormal];
    [cell addSubview:deleteButton];

    priceMark = [[UILabel alloc]initWithFrame:CGRectMake(200, 8, 60, 25)]; //150, 8, 65, 25
    priceMark.backgroundColor = [UIColor clearColor];
    priceMark.font = [UIFont fontWithName:@"Arial" size:14];
    [cell addSubview:priceMark]; 

    qtyLabel = [[UILabel alloc]initWithFrame:CGRectMake(160, 8, 65, 25)]; //225, 8, 60, 25
    qtyLabel.backgroundColor = [UIColor clearColor];
    qtyLabel.font = [UIFont fontWithName:@"Arial" size:14];
    [cell addSubview:qtyLabel];
}


 nameLabel.text = [[itemsArray objectAtIndex:indexPath.row] objectForKey:@"itemname"];
  priceMark.text = [NSString stringWithFormat:@"Rs: %@",[[itemsArray 
  objectAtIndex:indexPath.row] objectForKey:@"amount"]];
   qtyLabel.text = [[itemsArray objectAtIndex:indexPath.row] objectForKey:@"qty"];

return cell;
    }
  • 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-29T09:16:04+00:00Added an answer on May 29, 2026 at 9:16 am

    You should not create new UILabels and UIButtons and adding them as a subview every time.
    Your problem here is that you add new ones every time.
    You should make a custom UITableViewCell with labels and buttons and set them.

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

Sidebar

Related Questions

I have a vector declared as a global variable that I need to be
I have an array that i want to make global, and i want to
In following program . I have one doubt. I have declared one global variable
I have a header file variable.h where i declare all my global variable.Then i
Can Dynamic libraries have global, local and static variables in linux? If yes, then
If i have global variable in A.dll, that depends on global variable in B.dll
I have some global variables in a Python script. Some functions in that script
I have a global event created and set/reset in a native C++ process that
I have a global header and footer that has a Database connection and a
I have few global methods declared in public class in my ASP.NET web application.

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.