简体   繁体   English

UIAlertView不显示

[英]UIAlertView not showing

I have a small problem with one of my UIAlertViews. 我的一个UIAlertViews有一个小问题。 I'm trying to show it, do some tasks, and then dismiss automatically. 我正在尝试显示它,执行一些任务,然后自动关闭。 This is the code I'm using currently: 这是我当前正在使用的代码:

callingTaxi = [[UIAlertView alloc] initWithTitle:@"" message:@"検索中" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
[callingTaxi show];
/* Do some tasks */
[callingTaxi dismissWithClickedButtonIndex:0 animated:YES];
[callingTaxi release];

However, the UIAlertView only shows half-way. 但是,UIAlertView仅显示一半。 I can see the background darken, but then after the tasks have completed, the alert view quickly appears and then disappears, again. 我可以看到背景变暗,但是在任务完成之后,警报视图迅速出现,然后又消失了。

Any ideas how to solve this issue? 任何想法如何解决这个问题?

Ben

It does show, but you dismiss it right away, instead of waiting for the user to do something, with 它确实显示,但是您可以立即将其关闭,而不是等待用户做某事

[callingTaxi dismissWithClickedButtonIndex:0 animated:YES];

There is no time for iOS to render it completely. iOS没有时间完全渲染它。 Anyway, this is not how dismissWithClickedButtonIndex is supposed to be used. 无论如何,这不是应该使用dismissWithClickedButtonIndex的方式。 What are you trying to achieve here? 您想在这里实现什么?

Edit: I guess you need to assign a delegate to the UIAlertView, and let the delegate handle what happens inside the AlertView. 编辑:我想您需要将委托分配给UIAlertView,并让委托处理AlertView内部发生的事情。

您不应该在与显示该函数相同的函数中关闭它,也不要通过计时器关闭它,或者对其他事件做出反应。

You don't need a delegate. 您不需要代表。 The problem is that the tasks you do must happen on a background thread, so the main thread is left alone to update the screen. 问题在于您必须执行的任务必须在后台线程上执行,因此主线程被单独保留以更新屏幕。

If you update your code to use blocks and dispatch queues, everything will work: 如果您更新代码以使用块和调度队列,那么一切都会起作用:

callingTaxi = [[UIAlertView alloc] initWithTitle:@"" message:@"検索中" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
[callingTaxi show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{
    /* Do some tasks */
    dispatch_async(dispatch_get_main_queue(), ^{
        // this code is back on the main thread, where it's safe to mess with the GUI
        [callingTaxi dismissWithClickedButtonIndex:0 animated:YES];
        [callingTaxi release];
    });
});

you should create a method for the alertview 您应该为alertview创建一个方法

- (void) alertView: (UIAlertView *) alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
// Do stuff
// Or if you have multiple buttons, you could use a switch

[callingTaxi release];

Or you could Autorelease.. 或者您可以自动发布。

But x3ro has given the correct answer, you call the method yourself instead of waiting for the user to press the button.. 但是x3ro提供了正确的答案,您可以自己调用该方法,而不必等待用户按下按钮。

the uialertview is dismissed by: [callingTaxi dismissWithClickedButtonIndex:0 animated:YES]; 通过以下方式关闭uialertview:[callingTaxi dismissWithClickedButtonIndex:0 animation:YES]; before the user can read it. 在用户可以阅读之前。

How long do you intend to have the end user read it??? 您打算让最终用户阅读多长时间?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM