Я совершенно новый в разработке iOS. Сегодня я узнал, что такое UIActivityIndicatorView. Теперь я создаю проект, где у меня есть табличное представление, я заполнил таблицу, используя разбор JSON. Теперь я добавил индикатор активности, который будет вращаться до того времени, пока таблица не будет заполнена. Я запустил индикатор активности, но он не останавливается. Можете ли вы сказать мне, где я ошибаюсь? Заранее спасибо. Это мой код.UIActivityIndicatorView не останавливается
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self fetchData];
self.mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_mySpinner.hidden = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) fetchData {
[_mySpinner startAnimating];
NSString *strURL = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"];
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
_webData = [NSMutableData data];
}
else{
//error
}
}
#pragma mark Url connection Delegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// A response has been received, this is where we initialize the instance var you created
// so that we can append data to it in the didReceiveData method
// Furthermore, this method is called each time there is a redirect so reinitializing it
// also serves to clear it
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to the instance variable you declared
[_webData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// The request is complete and data has been received
// You can parse the stuff in your instance variable now
// self.data parse
NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:self.webData options:kNilOptions error:nil];
self.arrDetail = [dict valueForKey:@"loans"];
[self.mySpinner stopAnimating];
self.mySpinner.hidden = YES;
[self.parserTable reloadData];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// The request has failed for some reason!
// Check the error var
}
#pragma mark Table View Delegates
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
NSDictionary *locationDict = [[self.arrDetail objectAtIndex:indexPath.row]valueForKey:@"location"];
UILabel *lbl1 = (UILabel*)[cell.contentView viewWithTag:1];
lbl1.text = [[self.arrDetail objectAtIndex:indexPath.row]valueForKey:@"name"];
UILabel *lbl2 = (UILabel*)[cell.contentView viewWithTag:2];
lbl2.text = [locationDict valueForKey:@"country"];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.arrDetail count];
}
@end
Где Вы добавляете вертушку к виду? Вы добавили 'UIActivityIndicatorView' в построитель интерфейсов? – rckoenes
В таблице. Да, точно. – Tirthendu
В коде, который вы отправили, вы создаете код 'UIActivityIndicatorView', но не добавляете его в представление.Если 'mySpinner' является' IBOutlet', подключенным в конструкторе интерфейсов, тогда нет необходимости создавать счетчик в коде. – rckoenes