0

ユーザーが「はい」をクリックしたかどうかを確認したい。たとえば、特定のアクションを実行したい。

これは私のコード行です:

UIAlertView* mes=[[UIAlertView alloc] initWithTitle:@"Are you sure?" message:@"this will start a new game" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];

    [mes show];

だから言いたいif user tap "yes" preform this action

これが私の方法です。ユーザーが「はい」をクリックした場合、新しいゲームを作成します。

- (IBAction)newGame:(UIButton *)sender {

    UIAlertView* mes=[[UIAlertView alloc] initWithTitle:@"Are you sure?" message:@"this will start a new game" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];

    [mes show];


    self.flipsCount = 0;
    self.game = nil;
    for (UIButton *button in self.cardButtons) {
        Card *card = [self.game cardAtIndex:[self.cardButtons indexOfObject:button]];
        card.unplayble = NO;
        card.faceUp = NO;
        button.alpha = 1;
    }

    self.notificationLabel.text = nil;
    [self updateUI];
}
4

3 に答える 3

0

UIAlertViewasのデリゲート メソッドを使用する

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if (buttonIndex == 1)//Yes
   {
       self.flipsCount = 0;
       self.game = nil;
       for (UIButton *button in self.cardButtons) 
       {
            Card *card = [self.game cardAtIndex:[self.cardButtons indexOfObject:button]];
            card.unplayble = NO;
            card.faceUp = NO;
            button.alpha = 1;
       }

       self.notificationLabel.text = nil;
       [self updateUI];
   }
   else//No 
   {
       //do something
   }
}
于 2013-03-12T09:21:59.477 に答える
0

次のメソッドを同じクラス (または として設定したクラスdelegate) に挿入します。

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
  if (buttonIndex == 0)
  {
    //User clicked ok
  }
  else
  {
    //User clicked cancel
  }
}
于 2013-03-12T09:23:14.010 に答える