我想在UIAccessibilityPostNotification
中通过UIAlertView
宣布一条消息。我的问题是警报视图关闭,消息突然停止(至少这是我的分析),只说了两个字。有没有办法让通知完成?我的代码如下:
//Function which calls UIAlertView
-(IBAction)foo:(id)sender
{
UIAlertView* myAlert = [[UIAlertView alloc] initWithTitle:@"Select to get more information"
message:@""
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"a",@"b",@"c", nil];
myAlert.tag=2;
[myAlert show];
//Code comes here immediately, even if I don't select anything on alertView.
NSLog(@"Does it come here? Yes!");
}
我的警报视图:
if ([alertView tag]==2)
{
//Some code
NSString* message = @"Long message";
if (UIAccessibilityIsVoiceOverRunning())
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, message);
else
NSLog(@"Voice-over is not running.");
}
我也准备改变我的代码逻辑。在我们在警报视图上选择一个选项后,我尝试了代码,以便我可以将message
变量设为全局并通过foo
函数发布通知。它并没有像预期的那样发生。 alertView关闭后程序停止。
是否存在任何解决方法?我是业余的iOS程序员,所以一些代码和解释会有所帮助。
P.S。我甚至可以使用除警报视图之外的其他内容,如果有的话。我只想要一个弹出窗口和一些按钮作为选择。
答案 0 :(得分:1)
IMO,您应该使用UIView
创建自定义弹出窗口,以向最终用户显示选项。然后首先显示弹出窗口,为用户提供选项,一旦用户选择其中一个(或选择其中一个后点击一个按钮),请拨打UIAlertView
以显示相关消息。
希望通过这种方式解决问题。