利用iOS的DTGridView实现横向滚动的tableview

fmms 12年前
     <p>我们都知道tableview的实现原理,就是创建当前可见个数的tablecell,滚动过程中只是更改不可见的tablecell到可见的位置并且更新数据。这样可以避免滚动很多屏不用创建相应的视图,这样就不会造成内存泄漏。</p>    <p>下面是实现的效果图:</p>    <p><a href="https://simg.open-open.com/show/3d390431ef2c677434dcb92ae761b2fa.png" target="_blank"><img style="cursor:pointer;" title="image" alt="利用iOS的DTGridView实现横向滚动的tableview" src="https://simg.open-open.com/show/3d390431ef2c677434dcb92ae761b2fa.png" width="164" height="244" /></a></p>    <p>下面是实现的代码:</p>    <pre class="brush:cpp; toolbar: true; auto-links: false;">    #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;     }</pre>    <p></p>    <p></p>    <p>项目源代码:<a href="/misc/goto?guid=4959500534247612412" rel="nofollow">http://easymorse-iphone.googlecode.com/svn/trunk/VTableViewDemo/</a></p>    <p>DTGridView 地址:<a href="/misc/goto?guid=4959500534422760016" rel="nofollow">https://github.com/danielctull/DTGridView</a></p>