CCTableView with non-fixed cell sizes

CCTableView with non-fixed cell sizes
0.0 0


I’ve modified CCTableView to allow for variable-sized cells, and thought it may save others some time. The modified version has the old “fast-path” (fixed sized cells), but will turn to table-walking if your CCTableViewDataSource returns “false” from hasFixedCellSize(). By default, it operates as before. To turn on the magic:

struct DataSource: public CCTableViewDataSource
  virtual bool hasFixedCellSize()
    return false;

  virtual CCSize cellSizeForIndex(CCTableView* table, unsigned int idx)
    return CCSize(...);
  /* ... */

Even though it has to walk the items to calculate a cumulative size, I’ve tested it with a few thousand items on an iPhone 4S with no problems. If your data set is huge, an offset-to-index mapping with a binary search could be implemented. I’ll leave that as an exercise to the reader.

Here it is in action:

And here’s the source:

iOS Simulator Screen shot Sep 11, 2012 4.42.27 AM.png (81.0 KB)


Oh, it’s an awesome work. Pretty good.


Could you make this sms demo to ExtensionTest/TableViewTest and send us a Pull Request?
I think lots of people need this feature. Thanks. :slight_smile:


My version has become pretty forked from the original with heuristic/average-height cell size estimations for large data sets etc. As I’ve been under a pretty tight deadline, it’s not the cleanest or most general CCScrollView anymore. When I get some time, I’d like to port back the useful things to CCScrollView in a more general way and issue a pull request. Unfortunately, that may be some weeks into the future, at best.


Hey Mike,
Please don’t let this useful feature sink. Do you have any time now?


tried it , but still doesnt work ,any demo please ??


My apologies for letting this linger, I’ve been contacted about it a few times.

The project that required this feature was cancelled shortly after my last post, and further work wasn’t really in a state to try to push. I no longer have access to the source repository, so the best I can do is what’s published in that Gist. I’ve meant to update you guys a few times, but my schedule kept letting it slip through the cracks.



a simple test for this variable-size cell


Thank you. :slight_smile:

小 苏 wrote:

a simple test for this variable-size cell


I’ve just sent a pull request with my implementation of the same feature: