0

In my picker view i have a "Custom" option which should popup a UIAlertView for the user to enter a new value, the value is saved in the plist source of the picker for future reference. xxxEditingDidBegin is being called repeatedly (never ending).

I presume its because my UIAlertView is triggering the picker to close.

How should I have done this?

- (IBAction)serviceTypeFieldEditingDidEnd:(UITextField *)sender 
{
    UIPickerView *picker = [sender.inputView.subviews objectAtIndex:0];
    NSString *selText = [serviceTypeArray objectAtIndex: [picker selectedRowInComponent:0]];
    sender.text = selText;

    if (NSOrderedSame==[selText compare:@"Custom"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Custom Role" 
                                                            message:@"Enter Role Title" 
                                                           delegate:self 
                                                  cancelButtonTitle:@"Cancel" 
                                                  otherButtonTitles:@"Ok", nil];
        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
        [alertView show]; 
    }
}
1
  • The issue is at 3rd line where you are setting sender.text = selText. This will call your UITextField delegate method every time the text is changed in textfield.
    – fibnochi
    Aug 28, 2012 at 12:02

2 Answers 2

0

Implement method like

- (IBAction)doSelectDate:(UIDatePicker *)sender 
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Hi" message:@"AlertView is shwoing" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
} 

and connect above method with ValueChanged Event of UIPickerView;

0

I fixed it like this

- (void)pickerView:(UIPickerView *)pickerView  didSelectRow:(NSInteger)row 
                                                inComponent:(NSInteger)component 
{
    NSString *rowString = [serviceTypeArray objectAtIndex:row];

    if ([rowString compare:@"Custom"] == NSOrderedSame)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Custom Role" 
                                                            message:@"Enter Role Title" 
                                                           delegate:self 
                                                  cancelButtonTitle:@"Cancel" 
                                                  otherButtonTitles:@"Ok", nil];
        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
        [alertView show]; 
    }
    else 
    {
        _serviceType.text = rowString;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.