Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在不同的时间和延迟逐个显示警报_Objective C_Xcode_Multithreading_Grand Central Dispatch_Objective C Blocks - Fatal编程技术网

Objective c 如何在不同的时间和延迟逐个显示警报

Objective c 如何在不同的时间和延迟逐个显示警报,objective-c,xcode,multithreading,grand-central-dispatch,objective-c-blocks,Objective C,Xcode,Multithreading,Grand Central Dispatch,Objective C Blocks,我必须以不同的时间延迟显示不同类型的警报,逐个显示警报。一个警报显示并停留一段时间,然后以延迟显示下一个警报…逐个显示这是我的代码 for ( int j = 0; j < [[CMAppData appData].arrayDistanceAlert count]; j++) { CMBeaconsDisplayList * displayData = [[CMAppData appData].arrayDistanceAlert objectAtIndex:j];

我必须以不同的时间延迟显示不同类型的警报,逐个显示警报。一个警报显示并停留一段时间,然后以延迟显示下一个警报…逐个显示这是我的代码

for ( int j = 0; j  < [[CMAppData appData].arrayDistanceAlert count]; j++)
{

        CMBeaconsDisplayList * displayData = [[CMAppData appData].arrayDistanceAlert objectAtIndex:j];


        if ([displayData.type isEqualToString:@"1"])
        {
            if ([displayData.type isEqualToString:@"1"] &&[displayData.displayForTime isEqualToString:@"0"]) {


                [self performSelector:@selector(dismissAlertView:) withObject:displayData afterDelay:[displayData.displayForTime intValue]*60];
            }

            else{

                double delayInSeconds =[displayData.displayForTime intValue] *10 ;

                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

                    NSLog(@"%f",delayInSeconds);

                    UIAlertView * alert =[[UIAlertView alloc] initWithTitle:displayData.title message:displayData.content delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"pause", nil];
                    alert.alertViewStyle =UIAlertViewStyleDefault;
                    [alert show];
                    [self performSelector:@selector(dismissUIAlertViewType:) withObject:alert afterDelay:15];

                });

                               }

        }

        else {

            if ([displayData.type isEqualToString:@"2"]&&[displayData.displayForTime isEqualToString:@"0"]) {

                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:displayData.title message:displayData.content delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
                [alertView show];
            }
            else{
                double delayInSeconds =[displayData.displayForTime intValue]*10;

                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

                    CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
                    UIView *customView  = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width-20, [UIScreen mainScreen].bounds.size.height-100)];
                    customView.backgroundColor = [UIColor blueColor];
                    [alertView setContainerView:customView];

                    UIScrollView  *MyScrollVw= [[UIScrollView alloc]initWithFrame:CGRectMake(0 ,0 ,[UIScreen mainScreen].bounds.size.width-20 ,[UIScreen mainScreen].bounds.size.height-100)];
                    MyScrollVw.delegate= self;
                    [MyScrollVw setShowsHorizontalScrollIndicator:NO];
                    [MyScrollVw setShowsVerticalScrollIndicator:YES];
                    MyScrollVw.scrollEnabled= YES;
                    MyScrollVw.userInteractionEnabled= YES;
                    MyScrollVw.contentSize= CGSizeMake([UIScreen mainScreen].bounds.size.width-20 ,1150);//(width,height)
                    [customView addSubview:MyScrollVw];


                    UILabel * lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, customView.frame.size.width, 30.0)];
                    lblTitle.text = displayData.title;
                    lblTitle.font = [UIFont fontWithName:@"Arial" size:15.0];
                    lblTitle.numberOfLines = 1;
                    lblTitle.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
                    lblTitle.adjustsFontSizeToFitWidth = YES;
                    lblTitle.minimumScaleFactor = 10.0f/12.0f;
                    lblTitle.clipsToBounds = YES;
                    lblTitle.backgroundColor = [UIColor clearColor];
                    lblTitle.textColor = [UIColor whiteColor];
                    lblTitle.textAlignment = NSTextAlignmentCenter;
                    [MyScrollVw addSubview:lblTitle];

                    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, lblTitle.frame.origin.y+lblTitle.frame.size.height, customView.frame.size.width, 250)];
                    displayData.image = [displayData.image stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
                    if(displayData.image && ![displayData.image isKindOfClass:[NSNull class]])
                    {
                    [imageView sd_setImageWithURL:[NSURL URLWithString:displayData.image] placeholderImage:nil options:/* DISABLES CODE */ (0) == 0 ? SDWebImageRefreshCached : 0];
                    }
                    if ([displayData.image length]==0)
                    {
                        [imageView setImage:[UIImage imageNamed:@""]];
                    }
                    [MyScrollVw addSubview:imageView];


                    NSString *videoString = displayData.video;
                    NSString *lastWord = [[videoString componentsSeparatedByString:@"="] lastObject];
                    self.playerView = [[YTPlayerView alloc]init];
                    self.playerView.frame = CGRectMake(0.0, imageView.frame.origin.y+imageView.frame.size.height, customView.frame.size.width, 250.0);
                    [self.playerView loadWithVideoId:lastWord playerVars:@{@"playsinline":@1}];
                    [MyScrollVw addSubview:self.playerView];



                    UIButton * btnPlayAudio = [[UIButton alloc] initWithFrame:CGRectMake(10.0,self.playerView .frame.origin.y+self.playerView .frame.size.height, customView.frame.size.width-20, 30)];

                    [ btnPlayAudio addTarget:self action:@selector(playAudio:) forControlEvents:UIControlEventTouchUpInside];
                    btnPlayAudio.backgroundColor = [UIColor redColor];
                    [btnPlayAudio setTitle:@"Play Audio" forState:UIControlStateNormal];
                    [btnPlayAudio setAccessibilityValue:displayData.audio];

                    [MyScrollVw addSubview:btnPlayAudio];

                    UILabel * lblDescription = [[UILabel alloc] initWithFrame:CGRectMake(10.0,btnPlayAudio .frame.origin.y + btnPlayAudio .frame.size.height, customView.frame.size.width-20, 100)];
                    lblDescription.text = displayData.content;
                    lblDescription.font = [UIFont fontWithName:@"Arial" size:15.0];
                    lblDescription.numberOfLines = 0;
                    [lblDescription sizeToFit];
                    lblDescription.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
                    lblDescription.adjustsFontSizeToFitWidth = YES;
                    lblDescription.minimumScaleFactor = 10.0f/12.0f;
                    lblDescription.clipsToBounds = YES;
                    lblDescription.backgroundColor = [UIColor clearColor];
                    lblDescription.textColor = [UIColor whiteColor];
                    lblDescription.textAlignment = NSTextAlignmentCenter;
                    [MyScrollVw addSubview:lblDescription];
                    [alertView show];

                    [self performSelector:@selector(dismissImageAlertView:) withObject:alertView afterDelay:15];

                });

                delayInSeconds = delayInSeconds * 10;

            }

        }


    }
for(int j=0;j<[[CMAppData appData].arrayDistanceAlert count];j++)
{
CMBeaconsDisplayList*displayData=[[CMAppData appData].arrayDistanceAlert对象索引:j];
如果([displayData.type isEqualToString:@“1”])
{
如果([displayData.type IsequalString:@“1”]&&[displayData.displayForTime IsequalString:@“0”]){
[self-performSelector:@selector(dismissAlertView:)with object:displayData afterDelay:[displayData.displayForTime intValue]*60];
}
否则{
double delayInSeconds=[displayData.displayForTime intValue]*10;
dispatch\u time\u t popTime=dispatch\u time(立即分派时间,延迟间隔*秒秒秒);
调度\u after(popTime,调度\u get\u main\u queue(),^(void){
NSLog(@“%f”,delayUnseconds);
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:displayData.title消息:displayData.content委托:自取消按钮:@“取消”其他按钮:@“暂停”,无];
alert.alertViewStyle=UIAlertViewStyleDefault;
[警报显示];
[自执行选择器:@selector(dismissionalertviewtype:)with object:alert afterDelay:15];
});
}
}
否则{
如果([displayData.type IsequalString:@“2”]&&[displayData.displayForTime IsequalString:@“0”]){
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:displayData.title消息:displayData.content委托:自取消按钮:@“取消”其他按钮:nil];
[警报视图显示];
}
否则{
double delayInSeconds=[displayData.displayForTime intValue]*10;
dispatch\u time\u t popTime=dispatch\u time(立即分派时间,延迟间隔*秒秒秒);
调度\u after(popTime,调度\u get\u main\u queue(),^(void){
CustomIOAlertView*alertView=[[CustomIOAlertView alloc]init];
UIView*customView=[[UIView alloc]initWithFrame:CGRectMake(0.0,0.0[UIScreen mainScreen].bounds.size.width-20[UIScreen mainScreen].bounds.size.height-100)];
customView.backgroundColor=[UIColor blueColor];
[alertView setContainerView:customView];
UIScrollView*MyScrollVw=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0[UIScreen mainScreen].bounds.size.width-20[UIScreen mainScreen].bounds.size.height-100)];
MyScrollVw.delegate=self;
[MyScrollVw设置ShowShorizontalscrollIndicator:否];
[MyScrollVw设置显示垂直滚动指示器:是];
MyScrollVw.scrollEnabled=是;
MyScrollVw.userInteractionEnabled=YES;
MyScrollVw.contentSize=CGSizeMake([UIScreen mainScreen].bounds.size.width-201150);/(宽度,高度)
[customView addSubview:MyScrollVw];
UILabel*lblTitle=[[UILabel alloc]initWithFrame:CGRectMake(0.0,0.0,customView.frame.size.width,30.0)];
lblTitle.text=displayData.title;
lblTitle.font=[UIFont fontWithName:@“Arial”大小:15.0];
lblTitle.numberOfLines=1;
lblTitle.baselineAdjustment=uibaselineadjustmentalgnbaselines;//或uibaselineadjustmentalgncenters,或UIBaselineAdjustmentNone
lblTitle.adjustsFontSizeToFitWidth=是;
lbltile.minimumScaleFactor=10.0f/12.0f;
lbltile.clipsToBounds=是;
lblTitle.backgroundColor=[UIColor clearColor];
lblTitle.textColor=[UIColor-whiteColor];
lblTitle.textAlignment=NSTextAlignmentCenter;
[MyScrollVw addSubview:lblTitle];
UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0.0,lblTitle.frame.origin.y+lblTitle.frame.size.height,customView.frame.size.width,250)];
displayData.image=[displayData.image stringByReplacingOccurrencesOfString:@“带字符串:@”%20“];
if(displayData.image&![displayData.image iskindof类:[NSNull类]]
{
[imageView sd_setImageWithURL:[NSURL URLWithString:displayData.image]占位符图像:无选项:/*禁用代码*/(0)==0?SDWebImageRefreshCached:0];
}
如果([displayData.image length]==0)
{
[imageView setImage:[UIImage ImageName:@”“];
}
[MyScrollVw addSubview:imageView];
NSString*videoString=displayData.video;
NSString*lastWord=[[videoString组件由字符串分隔:@“=”]lastObject];
self.playerView=[[YTPlayerView alloc]init];
self.playerView.frame=CGRectMake(0.0,imageView.frame.origin.y+imageView.frame.size.height,customView.frame.size.width,250.0);
[self.playerView loadWithVideoId:lastWord playerVars:@{“playsinline”:@1}];
[MyScrollVw addSubview:self.playerView];
UIButton*btnPlayAudio=[[UIButton alloc]initWithFrame:CGRectMake(10.0,self.playerView.frame.origin.y+self.playerView.frame.size.height,customView.frame.size.width-20,30)];
[btnPlayAudio addTarget:self action:@selector(playAudio:)for ControlEvents:UIControlEventTouchUpInside];
btnPlayAudio.backgroundColor=[UIColor redColor];
alert('Before the Delay');

function afterDelay() {
    alert('After the Delay');
}

setTimeout(afterDelay, 2000);