【发布时间】:2011-06-22 17:56:38
【问题描述】:
我正在开发这款 iPhone 应用程序,它具有基本的登录 - 注销功能。要求是执行如下注销操作。
- 首先使用 UIAlertView 获得用户的确认
- 在服务器中处理注销过程时显示正在进行的注销警告框
服务器逻辑尚未实现,但在显示第二个正在进行的警报框时我遇到了问题。问题是,没有显示警报框,而是主线程只是进入睡眠状态并进入根视图控制器。谁能帮我解决这个问题。
以下是我的代码:
注销操作:
-(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? 但我仍然无法让它工作。
请问谁能帮帮我?提前致谢。
【问题讨论】:
标签: iphone objective-c uinavigationcontroller uialertview