基本的なログインログアウト機能を備えたこのiPhoneアプリケーションを開発しています。以下のようなログアウトアクションを実装する必要があります。アラートが表示されない - (void)alertView:clickedButtonAtIndex:method
- まずUIAlertView
- を使用して、ユーザーの確認を得る、ログアウト処理がサーバ
で扱われている間、サーバーロジックがまだ実装されていない、ログアウト進行中のアラートボックスを表示しますしかし、この2番目の進行中の警告ボックスを表示するときに問題に直面しています。問題は、アラートボックスが表示されず、代わりにメインスレッドだけがスリープ状態になり、ルートビューコントローラに移動することです。誰も私にこの問題を助けることができますか?
私のコードを以下に示します。
ログアウトアクション:
-(IBAction)logOut
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really Want to Log Out?"
message:@"If you continue you will be redirected to Home page,
where you have to sign in again. \n\nContinue?"
delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Continue", nil];
[alert show];
[alert release];
}
次のように(ユーザーがクリックしたボタン)、ユーザの入力が処理されます...
-(void)alertView:(UIAlertView *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[NSThread detachNewThreadSelector:@selector(dataProcessor)
toTarget:self withObject:nil];
[NSThread sleepForTimeInterval:3];
[self.navigationController popToRootViewControllerAnimated:YES];
} else {
// do nothing
}
}
dataProcessor()は、次のように実装されています。
-(void)dataProcessor {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Signing out...\n\nPlease Wait..."
message:nil delegate:self cancelButtonTitle:nil
otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width/2,
alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[pool release];
}
この手法を使用すると、このアラートはUIActivityIndicatorで表示されません。何が起きるかは、ウェルカムビューコントローラがブラックアウト(私は[NSThread sleepForTimeInterval:3]のために考えられます)となり、ルートビューコントローラに戻ります。
また、この記事で説明したアラート付きのタグを使用しようとしました。 Show Alert in clickedButtonAtIndex?しかし、まだ私はこれを動作させることができません。
誰でもお手伝いできますか?前もって感謝します。
こんにちはDeepak、 まず最初に、私の質問に非常に詳細に答えてくれてありがとう。私はちょうどあなたのような答えが私をたくさん助けてくれるようにiPhoneプログラミングを始めています。 私はあなたの措置に従い、要件を満たすことができました。 もう一度、Deepakのヘルプに感謝します。 :) – mmmrbm