调用reloadData时表视图更改位置

时间:2014-11-05 12:55:35

标签: ios objective-c uitableview

我有一个表视图,它在给定的初始位置(顶部)设置。如果用户点击屏幕顶部,则表格视图会动画下来,因此会更改位置。问题是,每当我在该表上调用reloadData时,表就会回到其初始位置。有没有办法阻止它?

- (void)didNavigateVertically:(int)direction
{
    self.lastDirection = direction;
    [self replaceStuff:YES];
}

- (void)replaceStuff:(BOOL)animated
{
    __weak HyContactsViewController * weakSelf = self;
    int direction = self.lastDirection;
    void (^completion)() = ^{

        HyContactsViewController * strongSelf = weakSelf;
        GLfloat y;

        if (direction == 1) {
            y = self.view.frame.size.height - kHyNavigationLineOffset;
        }

        else {
            y = kHyNavigationLineOffset;
        }

        // Replace the contacts table down
        CGRect frame = strongSelf.contactsTableView.frame;
        frame.origin.y = y;
        [strongSelf.contactsTableView setFrame:frame];

    if (animated) {

        [UIView animateWithDuration:kHyVerticalAnimationDuration
                              delay:0.0f
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:completion
                         completion: nil];
    }

    else {
        completion();
    }
}

请注意,位移不一定是动画的。我在replaceStuff:中调用了viewDidAppear:,因为滑到另一个视图也会导致同样的问题(但这已经修复了)。

注意:从父视图控制器调用didNavigateVertically:,该控制器负责检测点击和平移。

0 个答案:

没有答案