1

違うタイプの警告を別の時間遅延で表示する必要があります。警告を1つずつ表示してください。 ..一つずつ表示これは私のコードです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:時間の経過後に関数を1回実行することができます。

alert('Before the Delay'); 

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

setTimeout(afterDelay, 2000); 
関連する問題