views:

218

answers:

2

I am using two table views (Main Table and Sub Table), one table inside other's cell. I am adding Sub Table in Main Table's cell content view. I am also using different Cell Identifier for both table cells.

Now, issue is : When - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

is called, very first time cell of Main Table is generated and when I scroll up/down they all are just dequeued, so it is expected and standard behavior and working fine. But, cell of Sub Table is getting created/allocated every time. It is not dequeued as it should be. I guess, its happening because Sub Table is part of Main Table's Cell Content view. But not sure and don't know how to resolve it. Can somebody help me to find the solution?

+1  A: 

You'r problem is exactly as you described it: The sub table UITableView object gets deallocated completely, and its cell queue along with it. You could try retaining the sub table views for each main table cell separately in an array or something, but this is ugly and prone to retain mess. Table views weren't designed for the way you are using them. In one project we faced the same design, we ended up drawing the sub tables as general views, with simple subviews in a for cycle for the sub table cells.

It's up to you to decide if you can go on the way you started or to change implementation to a different approach, but if you don't need scrolling and cell-reusing inside the main table cells I recommend you abandon the sub table being a UITableView approach completely.

rage
A: 

I had the exact same problem. It is because the example tutorial uses deque, I just changed it for the pointer to go to the cell instead of deque.

cellForRowAtIndexPath:indexPath

Worked for me.

Matt Davis