0

在我的选择器视图中,我有一个“自定义”选项,它应该弹出一个 UIAlertView 供用户输入新值,该值保存在选择器的 plist 源中以供将来参考。xxxEditingDidBegin 被重复调用(永无止境)。

我认为它是因为我的 UIAlertView 正在触发选择器关闭。

我应该怎么做?

- (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]; 
    }
}
4

2 回答 2

0

我这样修

- (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;
    }
}
于 2012-08-31T10:48:56.377 回答
0

实现方法如

- (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];
} 

并将上述方法与 UIPickerView 的 ValueChanged 事件连接起来;

于 2012-08-28T10:28:20.990 回答