我需要让 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/