0

也许有更好的方法,但我想在用户点击 UIalertView 中的按钮时弹出一个选择列表。我希望在警报视图仍然可见时弹出此列表,并在用户点击选择列表中的项目时关闭所有内容。

我想我可以通过将列表添加为 UIAlertView 中的子视图并保持 UIalertView 在 while 循环中显示 NSRunLoop 并弹出选择列表设置的标志。但是,我无法让它工作,因为在 while 循环回到 NSRunLoop 之前没有设置标志。第二次点击会让它退出 while 循环,但这不是我想要的。

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{
   CGRect popUpPickerFrame = alertView.frame;
   PopUpPicker *popUpPicker = [[PopUpPicker alloc] initWithFrame:CGRectMake(popUpPickerFrame.origin.x +150,popUpPickerFrame.origin.y-50,115,250)];
   popUpPicker.delegate = self;
   popUpPicker.aList = [NSArray arrayWithObjects:@"General Plan", @"Light Plan", @"Melatonin Plan", @"Bed Times", @"Done", nil];
   popUpPicker.tag = 10;
   [alertView addSubview:popUpPicker];

   while (popUpPicker.tag == 10) {
       [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
                             beforeDate:[NSDate distantFuture]];
   }
   [popUpPicker release];
}

我将 popUpPicker.tag 设置为用户在 tableView:didSelectRowAtIndexPath: 列表的方法中点击的行,然后调用列表委托方法。

我可以让弹出列表正常工作,但只有在 UIAlertView 关闭之后。

谢谢你的帮助。

约翰

4

1 回答 1

0

您的工作流程不适用于 UIAlertView 的概念。它并非旨在在您按下某个按钮后在列表中提供选择。WWDC 2011 上有人说“不要与框架抗争”。这个建议只适合你。避免警报,除非它们确实需要,考虑为您的任务使用操作表,或在 ViewController 中实现工作流。

于 2011-12-23T23:16:07.607 回答