开发者

NSRunLoop timing issue

开发者 https://www.devze.com 2023-02-12 15:53 出处:网络
Maybe there is a better way, but I want to pop a choice list when a user taps a button in a UIalertView. I would like this list to pop while the alert view is still visible and have everything close w

Maybe there is a better way, but I want to pop a choice list when a user taps a button in a UIalertView. I would like this list to pop while the alert view is still visible and have everything close when the user taps an item in the choice list.

I thought I could do it by adding the list as a subview in the UIAlertView and keep the UIalertView displayed with an NSRunLoop in a while loop that pops with a flag set by the choice list. I cannot get this to work, however, because the flag does not get set before the while loop drops back into the NSRunLoop. A second tap will get it to drop out of the while loop but that is not what I want.

- (void)alertView:(UIAlertView *)aler开发者_运维百科tView 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];
}

I am setting the popUpPicker.tag to the row the user taps in the tableView:didSelectRowAtIndexPath: method of the list which then calls the lists delegate method.

I can get the popup list to work fine but only after the UIAlertView closes.

Thanks for any help.

John


Your workflow is not applicable to concept of UIAlertView. It is not designed to provide choices in the list after you press some button. Somebody on WWDC 2011 said "Don't fight the framework." This advice is just for you. Avoid alerts except they are really needed, consider using action sheets for your task, or implement the workflow in ViewController.

0

精彩评论

暂无评论...
验证码 换一张
取 消