【发布时间】:2014-11-23 19:40:59
【问题描述】:
我无法解决的问题是我的视图中的 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 不为空,实际上这是我在 NSLog 时得到的:
<UIActivityIndicatorView: 0x16e91ed0; frame = (150 274; 20 20); hidden = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x16e91f90>>
【问题讨论】:
-
你检查过包含代码 [UIActivityIndicatorView startAnimating]; 的 else 块吗?执行?您的 NSLog 显示 UIActivityIndicatorView 已隐藏(隐藏 = YES);?
-
是的,我刚刚检查过了,else 块正在执行。
-
由于 _activityIndicatorView.hidesWhenStopped = YES; 显示为 HIDDEN;
标签: ios objective-c uisearchbar uisearchdisplaycontroller uiactivityindicatorview