开发者

how can i remove data from my table view on a button click?

开发者 https://www.devze.com 2023-03-12 15:05 出处:网络
how can i remove datas from my table vie on a button click. i added 5 images in to my table view .next time i am adding only 3 images but the last 4 and 5 images will not remove from my table view .

how can i remove datas from my table vie on a button click. i added 5 images in to my table view .next time i am adding only 3 images but the last 4 and 5 images will not remove from my table view . can any one provide me开发者_如何学运维 a good way to do it.

my code is

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


 static NSString *CellIdentifier = @"Cell";

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
 }


      if(indexPath.row == 0)
      {
       UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,100,125)];

       if([imageArray count]>0)
       {
       imageView1.image = [imageArray objectAtIndex:0];
       [cell.contentView addSubview:imageView1];
       [imageView1 release];
       }
       if([imageArray count]>1)
       {
       UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(150,5,100,125)];
       imageView2.image = [imageArray objectAtIndex:1];
       [cell.contentView addSubview:imageView2];
       [imageView2 release];
       }
       if([imageArray count]>2)
       {
       UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(310, 5, 100, 125)];
       imageView3.image = [imageArray objectAtIndex:2];
       [cell.contentView addSubview:imageView3];
       [imageView3 release];
       }
       if([imageArray count]>3)
       {
       UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(460,5,100,125)];
       imageView4.image = [imageArray objectAtIndex:3];
       [cell.contentView addSubview:imageView4];
       [imageView4 release];
       }

      }
      else if(indexPath.row == 1)
      {
       if([imageArray count]>4)
       {
       UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,100,125)];
       imageView5.image = [imageArray objectAtIndex:4];
       [cell.contentView addSubview:imageView5];
       [imageView5 release];
       }
       if([imageArray count]>5)
       {       
       UIImageView *imageView6 = [[UIImageView alloc] initWithFrame:CGRectMake(150,5,100,125)];
       imageView6.image = [imageArray objectAtIndex:5];
       [cell.contentView addSubview:imageView6];
       [imageView6 release];
       }

       if([imageArray count]>6)
       {
       UIImageView *imageView7= [[UIImageView alloc] initWithFrame:CGRectMake(310, 5, 100, 125)];
       imageView7.image = [imageArray objectAtIndex:6];
       [cell.contentView addSubview:imageView7];
       [imageView7 release];
       }

and on a button click i am removing all object from my array. and adding only 3 images to it. then calling myTableView.reloadData();

but the first three is changing and remaining 4 & 5 are still there not removing.


Just a hunch, but you might want to check your implementation of tableView:numberOfRowsInSection:

Please post that if you're still having trouble.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号