iphone:UIAlertView 不会消失并阻止 UIProgressView
我有一个 UIAlertView 询问用户是否要复制一堆联系人。用户单击“继续”后,我希望 AlertView 消失,并替换为显示加载速率的 UIProgressView。
一切正常,除了用户单击“继续”后警报仍保留在 XIB 上,并且直到整个进程运行后警报才会消失。一旦它消失,UIProgressView 栏就会出现,但此时它已达到 100%。
如何立即清除屏幕上的 UIAlertView 并显示进度条不断增长。
这是代码。感谢您的帮助。
-(IBAction)importAllAddressBook:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Import ALL Contacts" message:@"Do you want to import all your Address Book contacts? (Please note that only those with a first and last name will be transfered)" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"NO STOP");
return;
}else {
NSLog(@"YES CONTINUE");
importAllContactsProgress.hidden = NO; // show progress bar at 0
[self importAllMethod];
}
}
// method to import all Address Book
-(void) importAllMethod {
importAllContactsProgress.progress = 0.0;
load names etc etc
I have a UIAlertView that asks a user whether they want to copy a bunch of contacts. After the user clicks "Continue," I want the AlertView to disappear to be replaced by a UIProgressView that shows the rate of loading.
Everything functions properly except that the alert remains on the XIB after the user clicks Continue, and it doesn't disappear until the entire process has run. As soon as it disappears, the UIProgressView bar appears but by then it has reached 100%.
How do I clear the UIAlertView off the screen immediately and show the progress bar growing instead.
Here's the code. Thanks for help.
-(IBAction)importAllAddressBook:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Import ALL Contacts" message:@"Do you want to import all your Address Book contacts? (Please note that only those with a first and last name will be transfered)" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"NO STOP");
return;
}else {
NSLog(@"YES CONTINUE");
importAllContactsProgress.hidden = NO; // show progress bar at 0
[self importAllMethod];
}
}
// method to import all Address Book
-(void) importAllMethod {
importAllContactsProgress.progress = 0.0;
load names etc etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在后台线程上执行导入:
您的导入方法会阻塞主线程并阻止发生任何 UI 操作。
You'll want to perform the perform the import on a background thread:
Your import method is blocking the main thread and preventing any UI actions from occurring.