gpt4 book ai didi

ios - UI 卡在 iOS 7 上,同时关闭从 iPad 上的 didSelectRowAtIndexPath 显示的警报

转载 作者:行者123 更新时间:2023-11-28 18:21:48 25 4
gpt4 key购买 nike

我有一段代码,当选择 TableView 中的一行时,将显示一个警报并等待该警报被解除。虽然它在装有 iOS 5 和 6 的 iPad 上运行良好,但在 iOS 7 上它在尝试关闭警报时卡住了。

为了说明这个问题,我创建了一个简单的主从应用程序并创建了一个简单的 MyAlert 类,它扩展了 UIAlertView 并符合 UIAlertViewDelegate:

@interface MyAlert : NSObject <UIAlertViewDelegate>
{
volatile BOOL completed;
UIAlertView * alert;
}

- (void) showAndWaitUntilDone:(NSString*)message;

@结束

MyAlert.m:

@implementation MyAlert

- (void) showAndWaitUntilDone:(NSString*)message
{
alert = [[UIAlertView alloc] initWithTitle:@"Alert"
message:message
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Other", nil];

if (alert)
{
alert.delegate = self;
[self showAndWaitUnitlDone];
}
}

- (void) showAndWaitUnitlDone
{
completed = NO;
[alert show];
while (!completed)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
}
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
completed = YES;
}

@end

然后我在我的 ViewController 中显示警报,如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[MyAlert showAndWaitUntilDone:@"test msg"];
}

效果: UIAlertView stuck on iOS 7

如前所述,这在 iOS 5 和 6 上运行良好。

如果我不阻塞主线程,一切似乎都正常,但是,如果我运行这段代码,例如从 UIButton 回调中,它就像一个魅力。

最佳答案

在 iOS 7 中似乎有一个错误,导致一旦 RunLoop 启动,UIAlertView 委托(delegate)将永远不会被调用。当等待 UIAlertView 的线程不是主线程时,它的行为完全相同。人们建议将 UIAlertView 与 block 一起使用或编写自定义警报 View 。

有关更多详细信息,请参阅 Apple 的开发者论坛主题:https://devforums.apple.com/message/887792

关于ios - UI 卡在 iOS 7 上,同时关闭从 iPad 上的 didSelectRowAtIndexPath 显示的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19097269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com