NSRunLoop计时问题

时间:2011-02-23 09:30:05

标签: iphone xcode uialertview nsrunloop

也许有更好的方法,但是当用户点击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:列表的方法,然后调用list delegate方法。

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

感谢您的帮助。

约翰

1 个答案:

答案 0 :(得分:0)

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