将一些记录加载到tableview - 下拉以刷新

时间:2012-01-24 16:13:50

标签: iphone objective-c cocoa-touch

在tableview中我们通常加载一些记录(例如:10条记录),然后如果用户想要更多,他就去点击下一个按钮,我们加载另外10条记录。

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

这可能吗?我怎么能修改代码才能做到这一点?

重要事实:

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

我如何以编程方式执行此操作?

1 个答案:

答案 0 :(得分:1)

看起来很奇怪的刷新方式,但为什么不:)

- (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]; 

处理它:

-(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