cocoa-touch - 使 UIAlertView 阻塞

标签 cocoa-touch ios

我需要让 UIAlertView 阻塞。因为我有功能,我需要返回 UIAlertView 选择。但问题是,在显示 UIAlertView 之后,我的函数代码正在进一步执行,所以我无法捕捉到 UIAlertView 选择(我可以在委托(delegate)方法中做到这一点,但我需要返回函数结果)。

我尝试使用 NSCondition 阻止 UIAlertVIew。但是代码不起作用。

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] ;
}

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

最佳答案

没有办法实现你想要的。只能通过委托(delegate)。你应该重新设计你的功能或者拒绝使用 UIAlertView

关于cocoa-touch - 使 UIAlertView 阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3753154/

相关文章:

ios - 如何将 UIAppearance 代理属性应用于 UILabel?

iphone - IBAction - 在连接到服务器之前做一些事情

ios - 在 XIB 之外设置 UITableViewCell 背景

ios - 将每个属性设置为 strong 有什么缺点?

ios - 如何将测试数据添加到PreviewProvider

ios - 如何在 Objective-C 中使用 buttonWithType 添加按钮样式?

ios - 如何设置 UIDatePicker View 的日期格式

swift - 如何在swift中离线缓存图像(没有互联网连接)?

iphone - 允许一个 View 支持多个方向,而其他 View 则不支持 iPhone

iphone - iOS App 内用户的密码/身份验证