私の NavigationController の RootViewController には UIButton があります。このボタンをクリックすると、サーバーからいくつかのデータがロードされ、最終的に新しいビューが表示されます。これには数秒かかることがあるので、その間に MBProgressHUD を表示して、何が起こっているかをユーザーに示したいと思います。しかし、うまくいきません。
データの読み込みと HUD の表示、すべてが私の prepareForSegue-Method で行われ、次のようになります。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"showAllPoints"])
{
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
HUD.labelText = @"Loading data";
HUD.detailsLabelText = @"Please wait...";
HUD.mode = MBProgressHUDModeAnnularDeterminate;
[self.navigationController.view addSubview:HUD];
[HUD showWhileExecuting:@selector(prepareJSONData:)
onTarget:self withObject:
[self getJSONData] animated:YES];
[self prepareJSONData:[self getJSONData]];
[segue.destinationViewController setPoints:pointsArray];
}
}
何も起こらないので、間違いはどこですか?何が問題なのですか?
編集: メソッド getJSON と prepareJSONData は次のとおりです。
-(NSData *)getJSONData
{
NSURL *url = [NSURL URLWithString:@"http://www.example.de/example.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
return urlData;
}
-(void)prepareJSONData:(NSData *)jsonData
{
NSError *error;
NSDictionary *wholeDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
allWutpunkteArray = [wholeDict objectForKey:@"points"];
}