title: Reloading table view in xcode
body: <p>I have a text box in my app with a button and a table view.Inside this table view i am creating image views which will display some images.Now when i enter a number say 5 in the text box and then click the button then 5 images are displayed on the table view out of which 4 images are in the first row .Now the problem comes if i enter number less than 5 say 3 then i have to get only 3 images in the table view but still i am getting 5 images and if i enter more than 5 then i am getting the desired number on the table view.My piece of code is:-</p>
  
  <pre><code>if([imageArray count] &gt;0)
  {
      [imageArray removeAllObjects];
  }
  
  int j = [text.text intValue];
  
  for(int i=0;i&lt;j;i++)
  {
     [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]]];
  }
  
  [tableView reloadData];     
  
   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return 5;
     }
     // Customize the appearance of table view cells.
     - (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]&gt;0)
      {
  
          imageView1.image=[UIImage imageNamed:@"CARRY.png"];
          imageView1.image = [imageArray objectAtIndex:0];
          [cell.contentView addSubview:imageView1];
          [imageView1 release];
      }
      if([imageArray count]&gt;1)
      {
  
          UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(150,5,100,125)];
          imageView2.image = [imageArray objectAtIndex:1];
          [imageView2 addSubview:button6];
          [cell.contentView addSubview:imageView2];
          [imageView2 release];
      }
      if([imageArray count]&gt;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]&gt;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]&gt;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]&gt;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]&gt;6)
      {
          UIImageView *imageView7= [[UIImageView alloc] initWithFrame:CGRectMake(310, 5, 100, 125)];
          imageView7.image = [imageArray objectAtIndex:6];
          [cell.contentView addSubview:imageView7];
          [imageView7 release];
      }
      if([imageArray count]&gt;7)
      {                           
          UIImageView *imageView8 = [[UIImageView alloc] initWithFrame:CGRectMake(460,5,100,125)];
          imageView8.image = [imageArray objectAtIndex:7];
          [cell.contentView addSubview:imageView8];
          [imageView8 release];
      }
  }
  
  else if(indexPath.row == 2)
  {
      if([imageArray count]&gt;8)
      {
          UIImageView *imageView8 = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,100,125)];
          imageView8.image = [imageArray objectAtIndex:8];
          [cell.contentView addSubview:imageView8];
          [imageView8 release];
      }
      if([imageArray count]&gt;9)
      {                           
          UIImageView *imageView8 = [[UIImageView alloc] initWithFrame:CGRectMake(150,5,100,125)];
          imageView8.image = [imageArray objectAtIndex:9];
          [cell.contentView addSubview:imageView8];
          [imageView8 release];
      }                           
  
  }
  
  
  
  
  return cell;
  
  }
  </code></pre>
  
  <p>I am clearing the array and again adding images to it then reloading the table view but why is the output then not coming according to the needs.Please help.</p>
  
  <p>Thanks,
  Christy</p>