在forin循环中,我需要呈现一个UIAlertController并在呈现下一个之前等待用户确认。我把它们放在一个forin循环中,但只有第一个出现(确认之后,其他的没有显示)。任何帮助都将非常感激。
答案 0 :(得分:2)
按下按钮时,您可以使用UIAlertController委托显示下一个警告。
制作全球警报索引:
<div class="flexcontainer">
<div class="iteminvisible">Other</div>
<div class="itemcenter">One</div>
<div class="itemright">Other</div>
</div>
使用NSDictionary中的警报详细信息制作全局NSArray,例如:
NSUInteger alertIndex = 0;
使用索引调用您的第一个警报,例如:
self.alerts = @[@{@"title":@"Alert", @"message":@"Message 1"}, @{@"title":@"Alert", @"message":@"Message 2"}];
和
...title:self.alerts[alertIndex][@"title"]...
在警报控制器委托的didClickButtonAtIndex:
中...message:self.alerts[alertIndex][@"message"]...
答案 1 :(得分:1)
This UIViewController扩展可以满足您的需求:
警报排队,fifo。 I.e.后来的阿勒等待,直到 用户回复以前的警报。
答案 2 :(得分:0)
我需要做一些类似于在我的应用中向用户显示提示的内容。 只是设法将它拼凑在一起,它运作良好,易于适应并添加到......
/////
// Alert Properties in @interface
////
@property NSOperationQueue *queue;
@property NSMutableArray* operationArray;
@property int operationCounter;
@property int operationTotal;
/////
// Alert Properties End
////
/////////
// Multi Alert Code Start
////////
- (void) alertCodeWithTitleString: (NSString*) titlestring AndMessageString:(NSString*)messagestring {
NSOperation *tempoperation = [NSBlockOperation blockOperationWithBlock: ^(void) {
NSString* tutTitleString = titlestring;
NSString* tutMessageString = messagestring;
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:tutTitleString
message:tutMessageString
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* dontshow = [UIAlertAction
actionWithTitle:@"Don't Show This Again"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
self.operationCounter++;
[self alertOperationCallMethod2];
}];
UIAlertAction* done = [UIAlertAction
actionWithTitle:@"Close"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
self.operationCounter++;
[self alertOperationCallMethod2];
}];
[alert addAction:done];
[alert addAction:dontshow];
[self presentViewController:alert animated:YES completion:nil];
});
} ];
self.operationTotal++;
[self.operationArray addObject:tempoperation];
}
-(void) alertOperationCallMethod1 {
self.operationCounter = 0;
self.operationTotal = 0;
self.queue = [[NSOperationQueue alloc] init];
self.operationArray = [[NSMutableArray alloc] init];
[self alertCodeWithTitleString:@"Title1" AndMessageString:@"Message1"];
[self alertCodeWithTitleString:@"Title2" AndMessageString:@"Message2"];
[self alertCodeWithTitleString:@"Title3" AndMessageString:@"Message3"];
// Just keep adding method calls here to add alerts
[self alertOperationCallMethod2];
}
-(void) alertOperationCallMethod2 {
if (self.operationCounter<self.operationTotal) {
[self.queue addOperation:self.operationArray[self.operationCounter]];
}
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//something here
[self alertOperationCallMethod1];
}
/////////
// Multi Alert Code End
////////
----
您需要做的就是在alertOperationCallMethod1
中添加另一个方法调用alertCodeWith .....方法的多个版本应该允许您自定义警报。
希望这有助于某人:)