Загрузка некоторых записей в таблицу - потяните, чтобы обновить - PullRequest
0 голосов
/ 24 января 2012

В виде таблицы мы обычно загружаем как несколько записей (пример: 10 записей), а затем, если пользователь хочет большего, он нажимает на следующую кнопку, где мы загружаем еще 10 записей.

Вместо того, чтобы нажимать кнопку для загрузки следующих 10 записей, я хочу, чтобы пользователь нажал на последнюю запись и затем загрузил еще 10 записей. Посмотрите на проект pull To Refresh . В этом случае пользователю потребуется некоторое время удерживать / тянуть первую запись, чтобы обновить страницу. Аналогичным образом я хочу, чтобы пользователь удерживал / извлекал последнюю запись, чтобы загрузить еще 10 записей.

Возможно ли это? и как я могу изменить код, чтобы сделать это?

Важные факты:

1.) Изображение стрелки должно всегда указывать на последнюю запись. 2.) Когда пользователь удерживает изображение внизу, должны загружаться еще 10 записей, и теперь изображение стрелки должно быть на 21-й записи (последней записи).

Как я могу сделать это программно?

1 Ответ

1 голос
/ 24 января 2012

выглядит как странный способ обновления, но почему бы и нет:)

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

и ву а ля

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...