利用iOS的DTGridView實現橫向滾動的tableview

fmms 12年前發布 | 45K 次閱讀 IOS Android開發 移動開發

我們都知道tableview的實現原理,就是創建當前可見個數的tablecell,滾動過程中只是更改不可見的tablecell到可見的位置并且更新數據。這樣可以避免滾動很多屏不用創建相應的視圖,這樣就不會造成內存泄漏。

下面是實現的效果圖:

利用iOS的DTGridView實現橫向滾動的tableview

下面是實現的代碼:

    #pragma mark DTGridViewDataSource Methods

    - (NSInteger)numberOfRowsInGridView:(DTGridView *)gv {
        return 1;
    }

    - (NSInteger)numberOfColumnsInGridView:(DTGridView *)gv forRowWithIndex:(NSInteger)index {
        return 20;
    }

    - (CGFloat)gridView:(DTGridView *)gv heightForRow:(NSInteger)rowIndex {
        return gv.frame.size.height;
    }

    - (CGFloat)gridView:(DTGridView *)gv widthForCellAtRow:(NSInteger)rowIndex column:(NSInteger)columnIndex {
        return gv.frame.size.width;
    }
    - (DTGridViewCell *)gridView:(DTGridView *)gv viewForRow:(NSInteger)rowIndex column:(NSInteger)columnIndex {
        MyTableCell *cell = (MyTableCell *)[gv dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"MyTableCell" owner:self options:nil] objectAtIndex:0];
            cell.identifier = @"cell";
        }
        [cell onShowCell];
        return cell;
    }

項目源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/VTableViewDemo/

DTGridView 地址:https://github.com/danielctull/DTGridView

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!