2012-07-12 60 views
2

进出口使用显示与警报查看活动指标:警报查看活动指示灯显示时间

UIAlertView *Alert= [[UIAlertView alloc] initWithTitle:@"Loading" 
               message:@"\n" 
               delegate:self 
            cancelButtonTitle:nil 
            otherButtonTitles:nil]; 

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
spinner.center = CGPointMake(139.5, 75.5); 
[Alert addSubview:spinner]; 
[spinner startAnimating]; 
[Alert show];  

[Alert dismissWithClickedButtonIndex:0 animated:YES]; 

的唯一的事情是它消失关闭屏幕真正的快,我想指定警报亮起的时间屏幕显示两秒钟,而不是现在显示的纳秒。我不确定如何去实现这一点,我会使用某种NSTimer,如果有的话,一些建议如何实现这一点将非常感激。谢谢。

+0

通常情况下,如果要显示微调那是因为你正在做的工作,为什么不把它驳回只要工作就完成了?或者你真的希望它被定时?如果你想要它是2秒,那么你会使用'NSTimer'。我不明白为什么你会觉得显示警告视图,并立即解雇,将有超过一毫秒显示不同的结果... – 2012-07-12 18:59:00

+0

当我行动使用Twitter的框架孤单的应用鸣叫似乎是约两倍的延迟从按钮按下到显示的twitter表单三秒钟。 Alert View(警报视图)显示大约5秒钟,并留出2.5秒的暂停时间。我试过'timer = [NSTimer scheduledTimerWithTimeInterval:(1.2/2.0)target:self selector:@selector(loading)userInfo:nil repeatats:YES]; '我只是得到异常,所以试图围绕 – JSA986 2012-07-12 19:23:05

+0

工作似乎仍然直觉把它作为一个计时器例外。您不应该假设在延迟期间应让警报视图显示的延迟。这是它的主要目的。收到信息后,您应该可以将解雇信息放在一个地方。 – 2012-07-12 19:31:34

回答

1

下面是我如何将着手解决在使用NSTimerNSInvocation问题的例子。我没有测试过,所以可能会遇到一些麻烦。

UIAlertView *Alert= [[UIAlertView alloc] initWithTitle:@"Loading" 
               message:@"\n" 
               delegate:self 
            cancelButtonTitle:nil 
            otherButtonTitles:nil]; 
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
spinner.center = CGPointMake(139.5, 75.5); 
[Alert addSubview:spinner]; 
[spinner startAnimating]; 
[Alert show]; 
NSMethodSignature *mySignature = [UIAlertView instanceMethodSignatureForSelector:@selector(dismissWithClickedButtonIndex:animated:)]; 
NSInvocation *myInvocation = [NSInvocation invocationWithMethodSignature:mySignature]; 
[myInvocation setSelector:@selector(dismissWithClickedButtonIndex:animated:)]; 
[myInvocation setTarget:Alert]; 
int buttonIndex = 0; 
bool isAnimated = YES; 
[myInvocation setArgument:&buttonClicked 
        atIndex:2]; 
[myInvocation setArgument:&isAnimated 
        atIndex:3]; 
NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:2 
              invocation:myInvocation 
              repeats:NO]; 

我仍然不认为这是问题的最佳答案。在大多数情况下,您应该使用指示器,直到完成工作,而不是基于时间,特别是不是可以改变或依赖于其他因素的时间。

因此正确答案应该是等到工作完成,并在该点驳回UIAlertView

+0

谢谢你,一分钱也用行动后解雇降到了现在,仍然发现我与编程的方式,感谢您的帮助,我将做正确的方式按你的意见。 – JSA986 2012-07-12 20:26:24