state of the table view is changing when scrolling table view in iphone

106 views Asked by At

I am trying to add two buttons dynamically label with add and remove. When clicking add button it should change label to remove and vice verse.

I am able to perform action for add or remove buttons dynamically but the state of the table view is changing its always keeping add buttons..

thanx

Let me add my code here.

I am creating UI button and adding label like in for loop.Is this right approach?

UIButton *btn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
btn.frame = CGRectMake(230, 25, 73, 40) ;
btn.tag = indexPath.row+1;
btn.titleLabel.font = [UIFont boldSystemFontOfSize:15];

for (int i=0;i<[myarrayone  count];  i++)
{ 
 for (int j=0; j<[[appDelegate AddingCartArray]   count]; j++) 
 {
  if([myarrayone objectAtIndex:i] == [[appDelegate AddingCartArray]  objectAtIndex:j])
  {
    [btn setBackgroundImage:[UIImage imageNamed:@"RemovetoCart.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(Remove:)  forControlEvents:UIControlEventTouchUpInside];
  } 
  else {
       [btn setBackgroundImage:[UIImage imageNamed:@"adtoCart.png"] forState:UIControlStateNormal];
       [btn addTarget:self action:@selector(addCartClicked:) forControlEvents:UIControlEventTouchUpInside];
  }
1

There are 1 answers

3
Bonnie On

in your button click method also reload the tableView

[myTableView reloadData];