UIAlert всплывающее окно после закрытия UIPicker - PullRequest
0 голосов
/ 29 сентября 2011

У меня есть 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;

}

Ответы [ 3 ]

2 голосов
/ 29 сентября 2011
//Init the done button with an action to show an alert
// and the target as self
self.myBarBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemDefault target:self action:@selector(showAlert:)]

Тогда ваше действие:

// Show the alert with the currently selected row index of the picker 
- (void)showAlert:(id)sender {
    NSUInteger selectedIndex = [myPickerView selectedRowInComponent:0];
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat@"Row %f selected!", selectedIndex + 1] message:[NSString stringWithFormat:@"Row %d / %d selected.", selectedIndex + 1, [self pickerView:myPickerView numberOfRowsInComponent:0]] autorelease];
    [alert show];
}
1 голос
/ 29 сентября 2011
-(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;
}

}
0 голосов
/ 29 сентября 2011

Элегантный способ: добавить делегата в анимацию вашего вида, см. UIView.h

  • (void) setAnimationDidStopSelector: (SEL) селектор
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)
[UIView setAnimationWillStartSelector:self];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
pickerView.transform = transform;
[UIView commitAnimations]; 

и реализовать этот метод:

- (void) animationFinished: (NSString *) animationID закончено: (BOOL) завершено контекст: (void *) контекст

voilà

...