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协议。

然后,在显示警报之前,您需要添加以下行:

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

只需添加当您单击 UIAlertView 上的任何按钮时触发的此方法。

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

希望能帮助到你...

于 2012-05-02T06:33:56.273 回答
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];
}

我收到消息“确定已选择”,但没有其他反应...

它终于奏效了,但以另一种方式! 我两个都换

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

[self viewDidLoad];
于 2014-05-12T10:40:16.680 回答