문제는 내가 두 개의 경고를 만들고 표시 할 때 두 번째 경고가 첫 번째 경고를 무시하고 첫 번째 경고가 닫힌 후에 표시된다는 것입니다. 너무 예뻐요.NSOperaionQueue 및 UIAlertView
NSOperationQueue를 사용하여 대기열 경고를 만들려고합니다. 몇 가지 알림을 추가 할 수 있으며 닫을 순서를 표시합니다. 하지만 나는 그렇게 할 수 없다. 내가 추가 한 작업은 순차적으로 수행되고, 이전 작업을 기다리는 것이다. 그것들은 병행하여 실행됩니다.
AlertOperation.h
#import <Foundation/Foundation.h>
@interface AlertOperation : NSOperation<UIAlertViewDelegate>
@property (nonatomic,assign) BOOL isFinishedAlert;
- (AlertOperation *)initWithAlert:(UIAlertView *)alert;
@end
AlertOperation.m 여기
#import "AlertOperation.h"
@interface AlertOperation()
{
UIAlertView *_alert;
}
@end
@implementation AlertOperation
@synthesize isFinishedAlert = _isFinishedAlert;
- (AlertOperation *)initWithAlert:(UIAlertView *)alert
{
self = [super init];
if (self)
{
_alert = alert;
_alert.delegate = self;
[_alert show];
}
return self;
}
- (void) main
{
_isFinishedAlert = NO;
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!_isFinishedAlert);
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
_isFinishedAlert = YES;
}
- (BOOL) isConcurrent
{
return NO;
}
@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];
메인에 [_alert show] 넣기 – Felix
예! 고맙습니다, @ phix23! 간단한 논리. – glebus