我有一个UIPicker,当选择一行时会触发UIAlert。我试图在按下UIPicker的“完成”按钮并关闭UIPicker后弹出警报。此时,当选择该行时,警报触发。因此,当有人滚动选择器中的每一行时,UIAlert会不断弹出。

谢谢你的帮助

这是“完成”按钮代码:

-(IBAction)done{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
    pickerView.transform = transform;
    [UIView commitAnimations];


}

这是一个选择器UIAlert代码的示例,其中显示了“ case 0”以及警报消息:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

UIColor *newColor;
switch (row) {
    case 0:
        newColor = [UIColor yellowColor];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
        [alert show];
        [alert release];

        myLabel.text = @"sometext";
        break;


}

最佳答案

-(IBAction)done{

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"message"     delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
        [alert show];
        [alert release];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
    pickerView.transform = transform;
    [UIView commitAnimations];
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

UIColor *newColor;
switch (row) {
    case 0:
        newColor = [UIColor yellowColor];

        myLabel.text = @"sometext";
        break;
}

}

关于iphone - 关闭UIPicker后弹出的UIAlert,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7592103/

10-09 16:52