Haoxiang Li bio photo By Haoxiang Li

OmniGridView Code (GitHub)


This is a half-finished grid view for iOS. Cause Apple’s UITableView only allows us to add and reuse vertical cells, we need to write our own scroll view when we want to have horizontal cells.


Drag the OmniGridView Folder to your project. Use the OmniGridView like any other UIView. Assign a delegate to OmniGridView and implement the OmniGridViewDelegate.

Please refer to the OmniGridTestViewController.m to see the information you need to provide.

这是一个半成品的Grid View。 因为Apple的UITableView只提供垂直滚动的表格,我们可能会需要水平滚动的表格。 这里提供一个全方向滚动包含单元格重用机制的Grid View。


把OmniGridView文件夹加入你的工程。就像使用UIView一样使用OmniGridView。 设置OminiGridView的delegate实现OmniGridViewDelegate。



#pragma mark OmniGridViewDelegate

@implementation OmniGridTestViewController (Private)

- (OmniGridCell *)gridCellAt:(OmniGridLoc *)gridLoc inGridView:(OmniGridView *)gridView {
    OmniGridCell *gridCell = [gridView dequeueReusableGridCell];
    if (!gridCell)
        gridCell = [[OmniGridCell alloc] init];
        gridCell.layer.borderColor = [UIColor blackColor].CGColor;
        gridCell.layer.borderWidth = 1.0f;
        gridCell.textLabel.textAlignment = UITextAlignmentCenter;
    gridCell.textLabel.text = [NSString stringWithFormat:@"(%d,%d)", gridLoc.row, gridLoc.col];
    return gridCell;

- (float)gridCellHeightInGridView:(OmniGridView *)gridView {
    return 200.0f;

- (float)gridCellWidthInGridView:(OmniGridView *)gridView {
    return 200.0f;

- (int)numberOfGridCellsInRow:(int)row inGridView:(OmniGridView *)gridView {
    return 12;

- (int)numberOfRowsInGridView:(OmniGridView *)gridView {
    return 12;