-
Notifications
You must be signed in to change notification settings - Fork 282
Tables and Grids Guide
MGBoxKit provides layout engines for tables and grids and two content providing APIs, one suitable for small tables and one suitable for large. The small table API is quick and easy to use and most suitable for static tables or dynamic tables with small data sets. For larger data sets it's most appropriate to use the dynamic API which supports box reuse and offscreen culling.
An example of a small table might be your app's settings view, with rows for changing various preferences, account management, etc. An example of a large table might be your app's main view that shows a long, dynamic list of items fetched from a server. Think something like Facebook's newsfeed or a Twitter stream.
The reason for two separate APIs should be recognisable to anyone who has tried to use UITableView
for a small table and found it overly awkward and troublesome for something that should be simple and quick. For many tables you don't need all that API bloat, and it just gets in the way.
The large table API also attempts to be easier and less cumbersome than the UITableView
/ UICollectionView
equivalents, though given the need for box reuse and offscreen culling, most of the same requirements exist and the concepts should feel familiar.
All tables and grids require an MGBox or MGScrollView container and MGLayoutBox content items (eg MGBox, MGLine). Think of it as similar to creating a UIScrollView
and adding subviews, with the main difference being that you add the content items to [boxes](-[MGLayoutBox boxes]) instead of to subviews
.
MGScrollView *scroller = [MGScrollView scrollerWithSize:self.view.size];
[self.view addSubview:scroller];
MGBox *container = [MGBox boxWithSize:self.view.size];
[self.view addSubview:container];
For small static tables and grids the easiest approach is to create and add box objects to a container's [boxes](-[MGLayoutBox boxes]) array, then call the container's [layout](-[MGLayoutBox layout]) or [layoutWithSpeed:completion:](-[MGScrollView layoutWithSpeed:completion:]) method.
For tables and grids of dynamic content you can use the same technique as for static content, or optionally use the boxProvider
approach. The choice of which approach to use should be based on how large you expect the data set to be. For large data sets or memory heavy boxes (eg boxes with many subviews) you should use the boxProvider approach, which supports box reuse and offscreen culling. This is similar to the approaches taken by UITableView
and UICollectionView
.