Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios5 Can';除非我注释掉自动解雇,否则我看不到我的alertView_Ios5_Uialertview_Uiactivityindicatorview - Fatal编程技术网

Ios5 Can';除非我注释掉自动解雇,否则我看不到我的alertView

Ios5 Can';除非我注释掉自动解雇,否则我看不到我的alertView,ios5,uialertview,uiactivityindicatorview,Ios5,Uialertview,Uiactivityindicatorview,我正在实现一个带有活动指示器的简单警报视图,以便在应用程序执行数据库还原时向用户显示。一切都很好,只是我看不到警报视图,除非我注释掉自动取消行(这里的最后一行) 好的,数据库的恢复相当快,但我仍然希望看到它,即使是一瞬间,不是吗?我可以看到屏幕在动画中变得有点暗,但仅此而已。我还试着放置一个for循环来延长时间,时间延长了,但仍然没有警报视图 警报视图的调用方式没有任何错误,因为如果我对discover进行注释,我就可以看到它…只有永远。有人有主意吗 在别人说之前,我尝试将alertView的委

我正在实现一个带有活动指示器的简单警报视图,以便在应用程序执行数据库还原时向用户显示。一切都很好,只是我看不到警报视图,除非我注释掉自动取消行(这里的最后一行)

好的,数据库的恢复相当快,但我仍然希望看到它,即使是一瞬间,不是吗?我可以看到屏幕在动画中变得有点暗,但仅此而已。我还试着放置一个for循环来延长时间,时间延长了,但仍然没有警报视图

警报视图的调用方式没有任何错误,因为如果我对discover进行注释,我就可以看到它…只有永远。有人有主意吗

在别人说之前,我尝试将alertView的委托更改为发布的
self
,但没有任何帮助。

// First we prepare the activity indicator view to show progress indicator
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[activityView setFrame:CGRectMake(121.0f, 50.0f, 37.0f, 37.0f)];
[activityView startAnimating];

// Then we put it in an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alertView addSubview:activityView];
[alertView show];

// Finally we operate the restore
[[SQLManager sharedSQL] restoreDatabase:[restoreDatabaseURL path]];

// And we can dismiss the alert view with the progress indicator
[alertView dismissWithClickedButtonIndex:0 animated:NO];
我不知道为什么会发生这种情况,但我偶尔也会遇到。我实现这种功能的一种方法是在下次调用时使用
performSelector:withObject:afterDelay:
,如下所示:

// First we prepare the activity indicator view to show progress indicator
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[activityView setFrame:CGRectMake(121.0f, 50.0f, 37.0f, 37.0f)];
[activityView startAnimating];

// Then we put it in an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alertView addSubview:activityView];
[alertView show];

// Finally we operate the restore
// [[SQLManager sharedSQL] restoreDatabase:[restoreDatabaseURL path]];
[[SQLManager sharedSQL] performSelector:@selector(restoreDatabase:) withObject:[restoreDatabaseURL path] afterDelay:0.25];


// And we can dismiss the alert view with the progress indicator
[alertView dismissWithClickedButtonIndex:0 animated:NO];

听起来它几乎是在瞬间自我毁灭。如果您添加for循环,它可能会冻结所有其他计算,这意味着您的活动视图在循环中断之前不会显示

您可以尝试使用NSTimer调用另一个函数来确定恢复是否完成

// Setup our the timer
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                  target:self 
                                                selector:@selector(checkRestore)
                                                userInfo:nil
                                                 repeats:YES];


// Timer function checking for completion
-(void)checkRestore {
    if (restore is complete) {
        [alertView dismissWithClickedButtonIndex:0 animated:NO];
    }
}

谢谢你,我一回到家就会试试这个,告诉你它是否有效。所以,我已经试过了,但没有效果,仍然没有警报。然后我尝试了其他的方法,使用这个方法来消除它本身…这是有效的!如果使用:
[alertView performSelector:@selector(dismissWithClickedButtonIndex:animated:)with object:nil afterDelay:2.0],我可以看到延迟。我想知道我是否可能不在主线上?我必须做其他测试,但谢谢你的建议@fnp和u肯定在主线程上,否则UI调用将一起失败。是的,我用debug检查过,我在主线程上。不幸的是,解雇后的电话仍然发生在……谢谢,我会尽快尝试。我会让你知道的。实际上我没有注意到你的代码的含义,基于我目前的设计,我不能使用它,因为我应该重写恢复数据库功能。如果真的没有别的办法,我就用这个。我相信这一切都会成功的,谢谢。