reloadData时UITableView消失了

时间:2013-12-05 13:05:17

标签: ios ipad uitableview animation frame

我有UIScrollView里面有一些元素。其中一个是UITableView。我需要隐藏这个表格视图,重新加载其内容并再次显示,但当我[self.tableView reloadData];表格从未出现时,它仍然隐藏。

- (void)hideTableMotivesAndReloadData
{
    NSLog(@"Hiding table and reloading data");

    // Hiding tableView
    [UIView animateWithDuration:0.5 animations:^{
        self.tableMotives.alpha = 0;
        self.textComments.alpha = 0;
    } completion:^(BOOL finished) {

        [self.tableMotives reloadData];

        [UIView animateWithDuration:1.5 delay:1.2 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseOut
        animations:^{
            self.tableMotives.alpha = 1;
            self.textComments.alpha = 1;
        } completion:^(BOOL finished) {
            //
        }];

    }];
}

有什么建议吗?谢谢!

编辑:

我在NSLog(self.tableMotives.description)来电之前和之后添加了reloadData,结果是:

在:

<UITableView: 0x1529bc00; frame = (-1 789; 770 420); clipsToBounds = YES; hidden = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x14d73960>; layer = <CALayer: 0x14d9a5c0>; contentOffset: {0, 0}>

后:

<UITableView: 0x1529bc00; frame = (-1 344; 770 81); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x14d73960>; layer = <CALayer: 0x14d9a5c0>; contentOffset: {0, 0}>

我在第二个完成块中手动更改帧,添加:

CGRect frame = self.tableMotives.frame;
frame.origin.y = 1000;
frame.size.height = 800;
[self.tableMotives setFrame:frame];

表格出现了......

编辑:

谢谢大家,在尝试了您的建议之前,我发现在调用reloadData时,tableView会重新显示为StoryBoard原始位置。似乎丢失了他的框架并获得storyboard中指定的框架。有人理解吗?

3 个答案:

答案 0 :(得分:0)

尝试tableview的隐藏属性

[self.tableMotives setHidden:YES];

并在重新加载后将hidden设置为no

[self.tableMotives setHidden:NO];

答案 1 :(得分:0)

试试这个

- (void)hideTableMotivesAndReloadData
{
NSLog(@"Hiding table and reloading data");

// Hiding tableView
[UIView animateWithDuration:0.5 animations:^{
    self.tableMotives.alpha = 0;
    self.textComments.alpha = 0;
} completion:^(BOOL finished) {

    [UIView animateWithDuration:1.5 delay:1.2 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseOut
    animations:^{
        self.tableMotives.alpha = 1;
        self.textComments.alpha = 1;
        [self.tableMotives reloadData];
    } completion:^(BOOL finished) {
        //
    }];
}];
}

答案 2 :(得分:0)

试试这个。它对我有用。

希望它有帮助...... :)

- (void)hideTableMotivesAndReloadData
{
    NSLog(@"Hiding table and reloading data");

    // Hiding tableView
    [UIView animateWithDuration:0.5 animations:^{
    self. tableMotives.alpha = 0;
    self.textComments.alpha = 0;
    } completion:^(BOOL finished) {
        [self.tableMotives reloadData];
    }];
}

- (void)showTableMotives{
    NSLog(@"Showing table and reloading data");

    // Showing tableView
    [UIView animateWithDuration:1.5 animations:^{
        self.tableMotives.alpha = 1;
        self.textComments.alpha = 1;
    } completion:^(BOOL finished) {
    }];
}

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Some other code if needed
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        //end of loading
        [self showTableMotives];
    }
}


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] init];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];

    return cell;
}