使用if语句更改标签文本 - obj c

时间:2013-02-28 22:59:09

标签: objective-c ipad cocoa-touch

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

    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会更改其文本。然后单击警报上的“确定”按钮我想更改label.text。我尝试过一个实例布尔值但不起作用。 为什么不工作呢?我需要做什么呢?

1 个答案:

答案 0 :(得分: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"];
}