1

UIAlertView が閉じられた後、ビューをリロードしたいと思います (viewWillDisappearビューとビューに対して実行しviewWillAppearます)。

それ、どうやったら出来るの?nil と self の両方に委任しようとしました。これが私のコードです。

- (IBAction)doStuffWhenUIButtonIsClicked:(id)sender
{
    int intSelection = [sender tag];
    NSString* strAlertTitle;
    NSString* strAlertMessage;
    if (intSelection == self.intCorrectChoice) {
        strAlertTitle = @"Correct tag!";
    }
    else {
        strAlertTitle = @"Sorry, incorrect tag!";
    }
strAlertMessage = @"The correct answer was 8.";

    self.answerReaction = [[UIAlertView alloc]
                           initWithTitle: strAlertTitle
                                 message: strAlertMessage
                                delegate: nil
                       cancelButtonTitle:@"Next Question"
                       otherButtonTitles:nil];
    [self.answerReaction show];
}

ご覧のとおり、ユーザーがいずれかの質問に回答した後、新しい質問をロードしたいと考えています。

4

3 に答える 3

5

UIAlertViewDelegateまず、プロトコルに準拠しているViewControllerを作成する必要があります。

次に、アラートを表示する前に、次の行を追加する必要があります。

self.answerReaction.delegate = self;

次に、didDismissWithButtonIndexデリゲートメソッドを実装します。

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    [self viewWillDisappear:YES];
    // load your new question
    [self viewWillAppear:YES];
}

それはそれの世話をする必要があります!

于 2012-05-02T05:28:19.070 に答える
0

それは私にはうまくいきません!私は持っている:

- (IBAction)OkButton:(id)sender {    

  // store your selected row
    NSUInteger selectedRow = [_intervalPicker selectedRowInComponent:0];    

    // Display a message to user
    if (selectedRow == CorrectAnswer) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct!" message:@"YAY!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

        [alert show];

        RightScoreNumber0 += 1;
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:@"Wrong answer" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

        [alert show];

        WrongScoreNumber0 += 1;
    }

}

そしてあなたが提案したように:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"OK was selected");  

    [self viewWillDisappear:YES];
    // load your new question
    [self viewWillAppear:YES];
}

「OKが選択されました」というメッセージが表示されますが、何も起こりません...

最終的にはうまくいきましたが、別の方法で!! 両方交換します

[self viewWillDisappear:YES];
[self viewWillAppear:YES];

[self viewDidLoad];
于 2014-05-12T10:40:16.680 に答える
0

UIAlertView の任意のボタンをクリックするとトリガーされるこのメソッドを追加するだけです。

- (void)alertView:(UIAlertView *)alertView  clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        [self viewWillDisappear:YES];
        [self viewWillAppear:YES];
    }
}

それが役に立てば幸い...

于 2012-05-02T06:33:56.273 に答える