The problem which I can't get through is that the UIActivityIndicatorView in my View doesn't start animating when I execute
[UIActivityIndicatorView startAnimating];
In
searchBarSearchButtonClicked
This is my code:
- (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];
}
}
Nothing happens until I clear the search results from the tableView connected to the UISearchBar using its cancel button.
I have tried and verified that
[UIActivityIndicatorView startAnimating];
actually works when called from other methods.
EDIT: I have also verified that my UIActivityIndicatorView is not null, in fact this is what I get when I NSLog it:
<UIActivityIndicatorView: 0x16e91ed0; frame = (150 274; 20 20); hidden = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x16e91f90>>
You cane use SVProgresshood , a famous class for activity indicator. Download it from here
Copy SVProgressHUD folder to your project.
to your required ViewController.
Where you start to Animate Activity indicator write :
And where to stop the activity indicator , write :
You can set your own status instead of "Loading.."
Hope it works.