私はこの問題で壁に頭をぶつけていて、助けが必要です。バックグラウンドでデータを読み込んでいる間に UIActivityIndicator を表示しようとしています。これが関連しているかどうかはわかりませんが、テーブルビューを読み込んでいます。インジケーターは表示されますが、回転しません...画面に触れない限り、またはテキストメッセージを受信した場合のように、読み込み中に何かが発生しない限り. コードは次のとおりです。
UIActivityIndicatorView *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
av.frame=CGRectMake(145, 160, 25, 25);
av.tag = 1;
[self.mTableView addSubview:av];
[av startAnimating];
[self performSelectorInBackground:@selector(load) withObject:nil];
私もこれを試しました:
UIActivityIndicatorView *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
av.frame=CGRectMake(145, 160, 25, 25);
av.tag = 1;
[self.view addSubview:av];
[av startAnimating];
[self performSelectorInBackground:@selector(load) withObject:nil];
最後の行をコメントアウトして試してみました-したがって、バックグラウンドスレッドを実行していません。viewDidLoad
メソッドとメソッドで両方のバージョンのコードを試しましたviewDidAppear
。
何か案は?
編集これが私のロード方法です
- (void)load {
NSString *post = [NSString stringWithFormat:@"id[]=%@", [ids objectAtIndex:0]];
for(int i = 1; i < ids.count; i++){
post = [NSString stringWithFormat:@"%@&id[]=%@", post, [ids objectAtIndex:i]];
}
NSURL *url=[NSURL URLWithString:@"http://myurl/instructions"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
/* when we user https, we need to allow any HTTPS cerificates, so add the one line code,to tell teh NSURLRequest to accept any https certificate, i'm not sure about the security aspects
*/
//[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
[self parseData:data];
[spinner stopAnimating];
}