使UIAlertView阻止 [英] Make UIAlertView blocking

查看:78
本文介绍了使UIAlertView阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使 UIAlertView 阻塞。因为我有函数,我需要返回 UIAlertView 选择。但问题是,在显示 UIAlertView 后,我的功能代码正在执行,所以我不能捕获 UIAlertView choice可以在委托方法中,但我需要返回函数结果)。

I need make UIAlertView blocking. Because i have function and i need to return UIAlertView choice. But problem is that after UIAlertView is shown my function code is executing further so i can't catch UIAlertView choice (i can do it in delegate methods, but i need to return function result).

我试图使 UIAlertVIew NSCondition 。但是代码不起作用。

I tried to make UIAlertVIew blocking with NSCondition. But the code don't works.

condition = [NSCondition new];
result = 0 ; 
[condition lock];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fingerprint" message:@"test" delegate:window_self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
[alert setDelegate:self];
[alert show];
while (result == 0) [condition wait];
[condition unlock] ;

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 [condition lock] ;
 if (buttonIndex == 0)
 {
  result = 2; 
 }
 else if (buttonIndex == 1)
 {
  result = 3 ;
 }
 [condition signal] ;
 [condition unlock] ;
}

也许如何修复此代码或任何其他建议?感谢

Maybe how to fix this code or any other suggestions ? Thanks

推荐答案

没有办法实现你想要的。只有通过代表。您应该重新设计您的功能或拒绝使用UIAlertView

There's no way to achieve what you want. Only through the delegate. You should redesign your function or refuse using UIAlertView

这篇关于使UIAlertView阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆