0

我有一个 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 
4

1 回答 1

2

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

[self performSelectorInBackground:@selector(importAllMethod)];

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

于 2011-07-28T23:01:30.317 回答