2011-02-23 50 views
0

也許有更好的方法,但我想在用戶點擊UIalertView中的按鈕時彈出選擇列表。我希望這個列表能夠在警報視圖仍然可見時彈出,並且在用戶點擊選擇列表中的項目時關閉所有內容。NSRunLoop計時問題

我認爲我可以通過在UIAlertView中添加列表作爲子視圖,並使UIalertView在顯示時使用NSRunLoop顯示在選擇列表中設置的標誌的while循環中。然而,我無法得到這個工作,因爲在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關閉後。

感謝您的任何幫助。

約翰

回答

0

您的工作流程不適用於UIAlertView的概念。它不旨在按下某個按鈕後在列表中提供選擇。 WWDC 2011上有人說:「不要打架」。此建議僅供您參考。除真正需要警告外,請避免提醒,考慮爲您的任務使用操作表,或在ViewController中實施工作流程。