刷新UITableViewData

时间:2011-05-18 17:18:16

标签: iphone xcode uitableview uiactivityindicatorview

我的 UITableView 顶部有 navigationBar 。我在navigationBar右侧有一个刷新按钮。

单击刷新按钮时,我需要启动一个活动指示器,刷新表并停止活动指示器。

-(void)refreshClicked{
    [spinner startAnimating];   //UIActivityIndicatorView object
    [appDelegate readJSONData]; //this is the method which populates the array
                                //for displaying in the tableview
}

我想知道如何在填充数组后刷新表,然后如何停止活动指示器。

谢谢:)

2 个答案:

答案 0 :(得分:5)

刷新表:

[tableView reloadData];

停止活动指示器:

[spinner stopAnimating];

- - - - - - - - 编辑

根据你的评论,我可以收集到你希望平滑地淡化微调器并重新加载tableview。

对于tableview:

您可以使用以下代码使用漂亮的淡入淡出动画重新加载tableview的各个部分:

[tableView reloadSections:(NSIndexSet *)sections withRowAnimation:UITableViewRowAnimationFade];

您的索引集包含要重新加载的所有部分,并且您还有重新加载动画的其他选项。看这里:UITableViewRowAnimations

要创建NSIndexSet,请参阅this link

至于你的微调器,你可以在调用stopAnimating之前将它淡化为alpha零:

-(void)fadeSpinner
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(stopAnimation)];

    spinner.alpha = 0;

    [UIView commitAnimations];
}

- (void)stopAnimation
{
    [spinner stopAnimating];
}

答案 1 :(得分:1)

重新加载数据:

[yourTableviewController.tableView reloadData];

如果您需要重新布局:

[yourTableviewController.tableView setNeedsDisplay]; 
[yourTableviewController.tableView setNeedsLayout];