如何在tableview上实现循环滚动 [英] how to implement cyclic scrolling on tableview

查看:344
本文介绍了如何在tableview上实现循环滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我在tableview的圆形滚动。

Could you please help me with circular scrolling in tableview please.

我想要的是,如果我向下滚动tableview,行应该以相反的方式 -
它应该出现向后移动现在从顶部回来),即基本上循环滚动。

I want that if I scroll down tableview, the rows should go in the reverse way -- it should appear that move back around (bottom rows go around and now come back down from the top) i.e, cyclic scrolling basically.

我如何做到这一点。任何建议。

How can I do so. Any suggestions please.

Thanx提前。

推荐答案

假循环滚动重复相同的单元格。在numberOfRowsInSection方法中,返回n乘以实际行数。确保n足够大。

You could "fake" the cyclic scrolling repeating the same cells all over again. In the numberOfRowsInSection method, return n times the actual number of rows. Make sure n is big enough.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return numberOfActualRows*100;
}



<以返回正确的单元格。

Then in the cellForRowAtIndexPath method (and elsewhere) use the mod operator (%) to return the proper cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger actualRow = indexPath.row % numberOfActualRows;
    ...
}

您可能想要隐藏滚动指标。

You may want to hide the sroll indicator.

self.tableView.showsVerticalScrollIndicator = NO;

您可能还希望将表格视图滚动到中间,然后再显示表格,罚款。

You may also want to scoll the table view to the middle before you display the table so scrolling backwards works fine.

[self.tableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow:[self tableView:self.tableView numberOfRowsInSection:0]/2 inSection:0]  atScrollPosition:UITableViewScrollPositionTop animated:NO];

当然,如果用户继续滚动,用户最终会碰到底部或顶部

Of course, the user would eventually hit the bottom or the top if he/she kept scrolling over and over.

这篇关于如何在tableview上实现循环滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆