我无法解决的问题是,执行视图时,UIView中的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>>
最佳答案
您可以使用SVProgresshood,这是活动指标的著名类。
从here下载
将SVProgressHUD文件夹复制到您的项目中。
#import "SVProgressHUD.h"
到所需的ViewController。
从哪里开始为“活动活动”指示器写:
[SVProgressHUD showWithStatus:@"Loading.."];
在哪里停止活动指示器,写:
[SVProgressHUD dismiss];
您可以设置自己的状态,而不是“正在加载..”
希望它能工作。
关于ios - UIActivityIndicatorView startAnimating在searchBarSearchButtonClicked中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27093434/