1

다른 시간 지연을 사용하여 다른 유형의 경고를 표시해야합니다. 경고를 하나씩 표시하십시오. 하나의 경고창을 표시하고 지연 시간을두고 다음 경고 표시를 유지하십시오. .. 하나씩 보여주기 이것은 내 코드입니다한 시간에 하나씩 경고를 표시하는 방법 시간과 지연

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; 

      } 

     } 


    } 
+1

설정 같은 당신이 특정 경고에 필요한 값을 전달 경고 생성을위한 코드, 'createAlertWithText : @ "텍스트"'후 지연 비트에 초점을 - 당신이 원하는 경우에 대한 논리를 작동 화재 경보, 경보가 나타나면 어떻게해야하는지 등등. '두뇌'와 '디스플레이'를 다른 방법으로 유지하십시오. –

답변

-1

setTimeout : 시간 간격 후에 한 번 기능을 실행할 수 있습니다.

alert('Before the Delay'); 

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

setTimeout(afterDelay, 2000);