搜索时显示活动指示器

时间:2014-07-03 15:26:00

标签: objective-c uiview

我正在开发一款可在线搜索照片的应用。当我按下搜索按钮时,我正在做的事情:

- (IBAction)searchPhotos:(id)sender
{
    if (internetReachable.isConnected) {
        _searchingView.hidden = FALSE;
        NSLog(@"Yoooouuuuu... You've got what I need!");
        dispatch_async(dispatch_get_main_queue(), ^{
            [dataHandler searchPublicFlickrPhotosByKeyword:_tfKeyword.text];
        });
        [self performSegueWithIdentifier:@"segueToPhotos" sender:self];
    } else {
        _alert = [[UIAlertView alloc]initWithTitle:@"No Connection" message:@"There seems to be a problem with your internet connection. Please check your connection and try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [_alert show];
    }
}

我遇到的问题是uiview:_searchingView不会显示。有任何想法吗?条件语句肯定是正确的,因为NSLog出现了。

1 个答案:

答案 0 :(得分:0)

用它喝了一些后,我发现队列应该如下设置:

if (internetReachable.isConnected) {
    _searchingView.hidden = FALSE;
    NSLog(@"Yoooouuuuu... You've got what I need!");
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
        [dataHandler searchPublicFlickrPhotosByKeyword:_tfKeyword.text];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self performSegueWithIdentifier:@"segueToPhotos" sender:self];
        });
    });
}