0

工作,我無法打通的問題是,UIActivityIndi​​catorView在我看來,不啓動動畫當我執行UIActivityIndi​​catorView startAnimating不,在searchBarSearchButtonClicked

[UIActivityIndicatorView startAnimating]; 

searchBarSearchButtonClicked 

這是我的代碼:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 
{ 
    [searchBar resignFirstResponder]; 

    NSString *causeStr = nil; 

    if ([CLLocationManager locationServicesEnabled] == NO) 
    { 
     causeStr = @"device"; 
    } 
    else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) 
    { 
     causeStr = @"app"; 
    } 
    else 
    { 
     [_activityIndicatorView startAnimating]; 

     _searchPlacesResults = [[NSMutableArray alloc] init]; 

     NSString * searchQuery = [searchBar text]; 

     FTGooglePlacesAPINearbySearchRequest *request = [[FTGooglePlacesAPINearbySearchRequest alloc] initWithLocationCoordinate:locationManager.location.coordinate]; 
     request.rankBy = FTGooglePlacesAPIRequestParamRankByDistance; 
     request.keyword = searchQuery; 
     request.radius = 500; 
     [self startSearchingPlaces:request]; 
    } 

    if (causeStr != nil) 
    { 
     NSString *alertMessage = [NSString stringWithFormat:@"You currently have location services disabled for this %@. Please refer to \"Settings\" app to turn on Location Services.", causeStr]; 

     [[[UIAlertView alloc] initWithTitle:@"Location Services Disabled" 
            message:alertMessage 
            delegate:nil 
          cancelButtonTitle:@"OK" 
          otherButtonTitles:nil] show]; 
    } 
} 

直到我清除搜索結果tableView使用其取消按鈕連接到UISearchBar。

我曾嘗試和驗證其他方法調用時

[UIActivityIndicatorView startAnimating]; 

實際工作。

編輯: 我也已經驗證了我的UIActivityIndi​​catorView不爲空,其實這是我所得到的,當我的NSLog它:

<UIActivityIndicatorView: 0x16e91ed0; frame = (150 274; 20 20); hidden = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x16e91f90>> 
+0

你檢查過else塊包含的代碼[UIActivityIndi​​catorView startAnimating]執行?你的NSLog顯示UIActivityIndi​​catorView是隱藏的(hidden = YES);? – russell 2014-11-24 05:13:03

+0

是的,我剛剛檢查過,其他塊正在執行。 – rambodrahmani 2014-11-24 10:05:42

+0

由於_activityIndi​​catorView.hidesWhenStopped = YES,它顯示HIDDEN; – rambodrahmani 2014-11-24 10:06:16

回答

1

您使用甘蔗SVProgresshood,著名的類活動的指標。 從here

複製SVProgressHUD文件夾下載到您的項目。

#import "SVProgressHUD.h" 

到你需要的ViewController。

你從哪裏開始到動畫活動指示燈寫:

[SVProgressHUD showWithStatus:@"Loading.."]; 

以及在何處停止活動的指標,寫:

[SVProgressHUD dismiss]; 

您可以設置的,而不是你自己的狀態「中..」

希望它有效。

+0

如果我找不到其他解決方案,那麼我會考慮按照您的建議使用第三方庫。謝謝。 – rambodrahmani 2014-11-24 10:08:20

+0

這是使用最廣泛的library.shortcut方法來處理活動indicator.best運氣 – Logic 2014-11-24 10:18:37

0

您是否設置了斷點來查看else語句是否被調用?如果是這樣,請嘗試以下操作:設置startAnimating主隊列裏面如下:

dispatch_async(dispatch_get_main_queue(), ^{ 
    [_activityIndicatorView startAnimating]; 
}); 
+0

我設置斷點,並調用else語句。我嘗試了你的代碼:我用'dispatch_async(dispatch_get_main_queue(),^ {_activityIndi​​catorView startAnimating]; })替換'[_activityIndi​​catorView startAnimating];'',但它不起作用... – rambodrahmani 2014-11-24 11:04:31

相關問題