0

我有UITableView一些UITableViewCells,当我单击特定单元格时,应用程序将从我的服务器下载一些信息。问题是:“我怎样才能立即显示*一个只有UIActivityIndicator在下载过程中动画并在下载完成时停止动画的视图?”

*注意:不应该在app其他奇怪的操作之后,必须是点击单元格后的第一件事。

4

1 回答 1

0

您可以使用以下方法在单个方法中启动和停止主线程上的活动指示器

- (void)showIndicatorAndStartWork
{

// start the activity indicator (you are now on the main queue)
    [activityIndicator startAnimating];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // do your background code here

        dispatch_sync(dispatch_get_main_queue(), ^{
            // stop the activity indicator (you are now on the main queue again)  
        [activityIndicator stopAnimating];
        });
    });
}

注意

我正在做一些背景的东西,所以我用过dispatch_async,如果你也想在后台下载一些东西,你也可以使用dispatch_async,否则你也可以在主线程上下载东西。

于 2015-05-25T11:55:35.773 回答