2016-06-23 7 views
0

私のアプリでは、2つのアクションシートを実行するオプションが必要な領域が1つあります。 1つのオプションに投票するためにTableViewの行に触れると、3つの選択肢、サムズアップ、サムダウン、または提案された日付を表示します。サムネイルをクリックすると、利用可能な日付を持つ別のアクションシートが表示されます。これで2枚目のシートがポップアップしますが、コードself dismissViewControllerのおかげで自動的に解除されます。どのように私がこれをより良くすることができるかに関するどんな考えですか?UIAlertControllerアクションシートをトリガーするアクションシート

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Vote" message:@"Please vote thumbs up or thumbs down for this activity. Vote only one time, please, except for Cricket who may vote again for Casey...who still doesn't have an iPhone. Cricket, use this power wisely." preferredStyle:UIAlertControllerStyleActionSheet]; 
    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 

     // Cancel button tappped. 
     [self dismissViewControllerAnimated:YES completion:^{ 
     }]; 
    }]]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Thumbs Up" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 



     UIAlertController *actionSheet2 = [UIAlertController alertControllerWithTitle:@"Date" message:@"What Date?" preferredStyle:UIAlertControllerStyleActionSheet]; 
     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 

      // Cancel button tappped. 
      [self dismissViewControllerAnimated:YES completion:^{ 
      }]; 
     }]]; 

     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Sunday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       //Sunday 
       [entry addObject:@"Sunday" forKey:@"DatesSuggested"]; 
       [entry saveInBackground]; 
       [self loadObjects]; 

      }]; 
     }]]; 

     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Monday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       //Sunday 
       [entry addObject:@"Monday" forKey:@"DatesSuggested"]; 
       [entry saveInBackground]; 
       [self loadObjects]; 

      }]; 
     }]]; 

     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Tuesday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       //Sunday 
       [entry addObject:@"Tuesday" forKey:@"DatesSuggested"]; 
       [entry saveInBackground]; 
       [self loadObjects]; 

      }]; 
     }]]; 


     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Wednesday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       //Sunday 
       [entry addObject:@"Wednesday" forKey:@"DatesSuggested"]; 
       [entry saveInBackground]; 
       [self loadObjects]; 

      }]; 
     }]]; 


     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Thursday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       //Sunday 
       [entry addObject:@"Thursday" forKey:@"DatesSuggested"]; 
       [entry saveInBackground]; 
       [self loadObjects]; 

      }]; 
     }]]; 


     [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Friday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [self dismissViewControllerAnimated:YES completion:^{ 
       //Sunday 
       [entry addObject:@"Friday" forKey:@"DatesSuggested"]; 
       [entry saveInBackground]; 
       [self loadObjects]; 

      }]; 
     }]]; 


     [self presentViewController:actionSheet2 animated:YES completion:^{ 

     } 
     ]; 







     NSInteger numberFor = [entry[@"VotesFor"] intValue]; 
     NSInteger newValue = numberFor + 1; 
     NSString *newVotesFor = [NSString stringWithFormat: @"%ld", (long)newValue]; 

     [entry setObject:newVotesFor forKey:@"VotesFor"]; 
     [entry saveInBackground]; 
     [self loadObjects]; 
     // Distructive button tapped. 
     [self dismissViewControllerAnimated:YES completion:^{ 
     }]; 
    }]]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Thumbs Down" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
     NSInteger numberAgainst = [entry[@"VotesAgainst"] intValue]; 
     NSInteger newValue1 = numberAgainst + 1; 
     NSString *newVotesAgainst = [NSString stringWithFormat: @"%ld", (long)newValue1]; 

     [entry setObject:newVotesAgainst forKey:@"VotesAgainst"]; 
     [entry saveInBackground]; 
     [self loadObjects]; 
     // OK button tapped. 

     [self dismissViewControllerAnimated:YES completion:^{ 
     }]; 
    }]]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"View Proposed Dates" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
     DetailsViewController *theDetails = [[DetailsViewController alloc] init]; 
     theDetails.theActivity = entry; 
     // OK button tapped. 
     [self.navigationController pushViewController:theDetails animated:YES]; 
     [self dismissViewControllerAnimated:YES completion:^{ 

     }]; 
    }]]; 

    // Present action sheet. 
    [self presentViewController:actionSheet animated:YES completion:nil]; 

答えて

0

もう1つを提示する前に最初に消してください。

[self dismissViewControllerAnimated:YES completion:^{ 
    [self presentViewController:actionSheet2 animated:YES completion:^{ 
    }]; 
}]; 
関連する問題