Ios NSOperaionQueue和UIAlertView

Ios NSOperaionQueue和UIAlertView,ios,uialertview,nsoperation,nsoperationqueue,Ios,Uialertview,Nsoperation,Nsoperationqueue,问题是,如果我创建并显示两个警报,则第二个警报将覆盖第一个警报,并在其关闭后显示第一个警报。太不漂亮了 我正在尝试使用NSOperationQueue创建队列警报。您可以添加一些警报,它们显示要关闭的序列。但我不能这样做,我会添加操作是按顺序执行的,等待前一个。它们是并行执行的 警报操作 #import <Foundation/Foundation.h> @interface AlertOperation : NSOperation<UIAlertViewDelegate&g

问题是,如果我创建并显示两个警报,则第二个警报将覆盖第一个警报,并在其关闭后显示第一个警报。太不漂亮了

我正在尝试使用NSOperationQueue创建队列警报。您可以添加一些警报,它们显示要关闭的序列。但我不能这样做,我会添加操作是按顺序执行的,等待前一个。它们是并行执行的

警报操作

#import <Foundation/Foundation.h>

@interface AlertOperation : NSOperation<UIAlertViewDelegate>

@property (nonatomic,assign) BOOL isFinishedAlert;

- (AlertOperation *)initWithAlert:(UIAlertView *)alert;

@end
下面是运行代码

UIAlertView *u1 = [[UIAlertView alloc] initWithTitle:@"" 
message:@"Hello i am first alert" delegate:nil 
cancelButtonTitle:@"OK" otherButtonTitles:nil];

UIAlertView *u2 = [[UIAlertView alloc] initWithTitle:@"" 
message:@"Hello i am second alert" delegate:nil 
cancelButtonTitle:@"OK" otherButtonTitles:nil];

NSOperation *alertOp1 = [[AlertOperation alloc] initWithAlert:u1];
NSOperation *alertOp2 = [[AlertOperation alloc] initWithAlert:u2];

alertsQueue = [[NSOperationQueue alloc] init];
[alertsQueue setMaxConcurrentOperationCount:1];

[alertsQueue addOperation:alertOp1];
[alertsQueue addOperation:alertOp2];

让这对你自己更容易。创建一个可变数组。当您要显示新警报时,请将其推送到阵列上。每次警报完成时(获取其委托消息),然后将下一个警报分派到主队列:

NSMutableArray *alerts;

... end of Alert Delegate message
if([alert count]) {
  UIAlert *alrt = [alerts objectAtIndex:0];
  [alerts removeObjectAtIndex:0];
  dispatch_async(dispatch_get_main_queue(), ^{ [alrt show]; } );
}

我将[_alertshow]移动到-(void)main方法,它成功了!谢谢@phix23的帮助

是的!谢谢你,@phix23!简单的逻辑。
NSMutableArray *alerts;

... end of Alert Delegate message
if([alert count]) {
  UIAlert *alrt = [alerts objectAtIndex:0];
  [alerts removeObjectAtIndex:0];
  dispatch_async(dispatch_get_main_queue(), ^{ [alrt show]; } );
}