Jayshree
Jayshree

Reputation: 281

UITableView's reused cells not getting drawn

I have created a tableview with grouped style. I have added this table to the subview of UIScrollView. I have calculated the size of the table according to the number of rows it has. So there is no scrolling for the tableView. I will be able to see all the cells.

For the first time the table works properly and shows all the cells. But my Problem is whenever I navigate to next page and come back and reload that table it is only rendering and redrawing the cells which were allocated. The cells which are getting reused are not getting redrawn. The tableView:cellForRowAtIndexPath: is also not getting called for those cells.

I am suspecting that since the scrolling of the tableview is disabled the cellForRowAtIndexPath method for the reused cells are not getting called and hence they are not getting rendered.

I have created the tableView in the following way

 m_TravellerDetailTable = [[UITableView alloc] initWithFrame: CGRectMake( 2.0f, 0, 315.0f, 370 ) style: UITableViewStyleGrouped ];
 float height = (tableViewCellHeight * [travellersArray count]);
 m_TravellerDetailTable.frame = CGRectMake(2, 0, 315, height);
 [m_TravellerDetailTable setBounces: NO];
 [m_TravellerDetailTable setScrollEnabled: NO];
 [m_BaseScrollView addSubview: m_TravellerDetailTable];

UITableViewDelegate Methods

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
   {
       return [travellersArray count];
   }

 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
   {
       return tableViewCellHeight;
   }

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

     static NSString *CellIdentifier = @"Cell";
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) 
     {

            cell = [[TravellerDetailCustomCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
     }


     TravellerDetailCustomCellView *customCell = (TravellerDetailCustomCellView *)cell;
     [customCell.textLabel setText:[travellerInfoFromDetailForm objectForKey:@"DOB"]];
  }

This snapshot shows the uitableview rendering all the cells

UITableView with all Cells

The Snapshot shows the uitableview rendering only upto "Adult 8" cell. After that the table is not rendering the remaining cells.

UITableView without reuesed cells

Upvotes: 0

Views: 531

Answers (2)

blackmilk
blackmilk

Reputation: 1

it's caused by UIScrollView.The UIScrollView cached the drawing of it's subviews. I advice you dont add UITableView to UIScrollView

Upvotes: 0

vikingosegundo
vikingosegundo

Reputation: 52227

it is rendering, but your frame is to small and the table view is cut off.

You should remove

[m_TravellerDetailTable setBounces: NO];
[m_TravellerDetailTable setScrollEnabled: NO];

Upvotes: 1

Related Questions