-1

我有一些 UILabel 和按钮。这是我的代码:

    if ([label.text isEqualToString:@"The three blue dots represents GPS towers. Click Go to advance"])
    {
        firstClick = [[UIAlertView alloc] initWithTitle:@"Welcome!"
                                                message:@"Blah, blah blah"
                                               delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
        [firstClick show];

        distanceLabel.text = @"Distance to first tower: 50 km";
        a = YES;
    }

    if (a)
    {
        label.text = @"Now you know that the distance to the first tower is 50 km. Click Go to advance";
    }

所有这些都在按钮的操作方法中。当按下按钮时,alertview 视图和 distanceLabel 更改其文本。然后单击警报上的 OK 按钮我想更改 label.text。我尝试过使用实例布尔值,但这不起作用。为什么那行不通,我该怎么办?

4

1 回答 1

0

如果您希望在按下警报视图按钮时发生操作,您应该实现协议方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    NSLog(@"button clicked at index %d", buttonIndex);
    NSLog(@"about to update a label.  this won't work if it's nil... %@", label);
    label.text = [NSString stringWithFormat:@"user clicked button %d", buttonIndex"];
}
于 2013-03-01T00:32:12.430 回答