我无法解决的问题是,当我执行时,我视图中的UIActivityIndicatorView无法启动动画
[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];
}
}
在我使用取消按钮清除连接到UISearchBar的tableView的搜索结果之前,没有任何反应。
我已经尝试并验证了
[UIActivityIndicatorView startAnimating];
从其他方法调用时实际上有效。
编辑: 我还验证了我的UIActivityIndicatorView不是null,实际上这是我在NSLog时得到的:
<UIActivityIndicatorView: 0x16e91ed0; frame = (150 274; 20 20); hidden = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x16e91f90>>
答案 0 :(得分:1)
你可以使用SVProgresshood,一个着名的活动指标类。 从here
下载将 SVProgressHUD 文件夹复制到您的项目中。
#import "SVProgressHUD.h"
到你需要的ViewController。
开始动画活动指示符写入:
[SVProgressHUD showWithStatus:@"Loading.."];
在哪里停止活动指示,请写:
[SVProgressHUD dismiss];
您可以设置自己的状态,而不是&#34;正在加载..&#34;
希望它有效。
答案 1 :(得分:0)
您是否设置了断点以查看是否正在调用else语句?如果是这样,请尝试以下操作:在主队列中设置startAnimating,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
[_activityIndicatorView startAnimating];
});