首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在将一些记录加载到tableview -下拉以刷新

问正在将一些记录加载到tableview -下拉以刷新
EN

Stack Overflow用户
提问于 2012-01-25 00:13:50
回答 1查看 814关注 0票数 0

在表视图中,我们通常加载几条记录(例如: 10条记录),然后如果用户想要更多记录,他会单击next按钮,在那里我们加载另外10条记录。

我希望用户下推最后一条记录,然后再加载另外10条记录,而不是单击一个按钮来加载下10条记录。看看pull To Refresh项目。在这种情况下,用户必须保持/拉取第一条记录一段时间以刷新页面。以类似的方式,我希望用户持有/拉出最后一条记录,以加载另外10条记录。

这个是可能的吗?我如何修改代码才能做到这一点呢?

重要事实:

1.)箭头图像应始终指向最后一条记录。2.)当用户按住图像时,应该加载另外10条记录,箭头图像现在应该在第21条记录(最后一条记录)上。

我如何通过编程来做到这一点呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-25 02:53:37

看起来像是一种奇怪的刷新方式,但为什么不:)

代码语言:javascript
复制
- (void)viewDidLoad {


    [super viewDidLoad];
    // Add a pinch gesture recognizer to the table view.
    UIPinchGestureRecognizer* pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
    [self.tableView addGestureRecognizer:pinchRecognizer];
    [pinchRecognizer release]; 

处理它:

代码语言:javascript
复制
-(void)handlePinch:(UIPinchGestureRecognizer*)pinchRecognizer {

    /*
     There are different actions to take for the different states of the gesture recognizer.
     * In the Began state, use the pinch location to find the index path of the row with which the pinch is associated, and keep a reference to that in pinchedIndexPath. Then get the current height of that row, and store as the initial pinch height. Finally, update the scale for the pinched row.
     * In the Changed state, update the scale for the pinched row (identified by pinchedIndexPath).
     * In the Ended or Canceled state, set the pinchedIndexPath property to nil.
     */

    if (pinchRecognizer.state == UIGestureRecognizerStateBegan) {

        [self updateForPinchScale:pinchRecognizer.scale atIndexPath:newPinchedIndexPath];
    }
    else {
        if (pinchRecognizer.state == UIGestureRecognizerStateChanged) {
            [self updateForPinchScale:pinchRecognizer.scale atIndexPath:self.pinchedIndexPath];
        }
        else if ((pinchRecognizer.state == UIGestureRecognizerStateCancelled) || (pinchRecognizer.state == UIGestureRecognizerStateEnded)) {
            self.pinchedIndexPath = nil;
        }
    }
}


-(void)updateForPinchScale:(CGFloat)scale atIndexPath:(NSIndexPath*)indexPath {

    if (indexPath && (indexPath.section != NSNotFound) && (indexPath.row != NSNotFound)) {
         // make update here if indexpath == last index path
         /* 
         Switch off animations during the row height resize, otherwise there is a lag before the user's action is seen.
         */
        BOOL animationsEnabled = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
            [self.tableView beginUpdates];
               // do any changes like inform user about download here
            [self.tableView endUpdates];


        [UIView setAnimationsEnabled:animationsEnabled];
    }
}

和vu a la

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8990156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档