iphone:UIAlertView没有消失并阻止UIProgressView

时间:2011-07-28 22:53:52

标签: 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 

1 个答案:

答案 0 :(得分:2)

您想要在后台线程上执行导入:

[self performSelectorInBackground:@selector(importAllMethod)];

您的导入方法阻止主线程并阻止任何UI操作发生。