多个UITextfields返回Null IOS

时间:2012-10-31 19:36:49

标签: objective-c ios uitextfield

我在表单视图中有多个文本字段。我想在用户点击按钮时附加它们。但是只有其中一个返回textfield中的值,其余的返回null。

·H

@property (nonatomic, strong) IBOutlet UITextField *textMonth;
@property (nonatomic, strong) IBOutlet UITextField *textDay;
@property (nonatomic, strong) IBOutlet UITextField *textYear;
@property (nonatomic, strong) IBOutlet UITextField *textMeetingName;

的.m

@synthesize textDay=_textDay;
@synthesize textMonth=_textMonth;
@synthesize textYear=_textYear;
@synthesize textMeetingName=_textMeetingName;


- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}
//this dismiss keyboard on ios
- (BOOL)textFieldShouldReturn:(UITextField *)textField {

        [_textMonth resignFirstResponder];
        [_textDay resignFirstResponder];
        [_textYear resignFirstResponder];
        [_textMeetingName resignFirstResponder];


    return YES;
}
//submit create folder request to dropbox
- (IBAction)sendCreateFolderRequest:(id)sender{

    if ([_textMonth.text intValue]>12 ||[_textMonth.text intValue]<1 ) {
        //alertview choose a number between 1 and 12
        [self popUpAlertview:@"Please choose a month between 1 and 12"];
    }
    else if ([_textDay.text intValue]>31 || [_textDay.text intValue]<1){
        //alert view choose a number between 1 and 31
        [self popUpAlertview:@"Please choose a day between 1 and 31"];
    }
    else if ([_textYear.text intValue]<0){
        //alert view please enter a correct year
        [self popUpAlertview:@"Please enter a correct year"];
    }
    else if ([_textMeetingName.text length]<=1){
        //alert view meeting name is too short please enter a longer name
         [self popUpAlertview:@"Name is too short. Please enter a longer name"];
    }
    else{

        NSString *sendFolderName=[NSString stringWithFormat:@"/Up2Date/%@.%@.%@.%@",_textMonth.text,textDay.text,textYear.text,textMeetingName.text];

        NSLog(@"Send folder name %@",sendFolderName);

    }

}

输入为11,12,13,asdaad 输出为Send folder name /Up2Date/11.(null).(null).(null)

奇怪的是我的if else方法如果字段值错误就会捕获,例如11,45,20它会像我预期的那样弹出警报视图。

那么似乎是什么问题?也许我不应该立刻让他们成为第一响应者?

1 个答案:

答案 0 :(得分:3)

更改

NSString *sendFolderName=[NSString stringWithFormat:@"/Up2Date/%@.%@.%@.%@",_textMonth.text,textDay.text,textYear.text,textMeetingName.text];

NSString *sendFolderName=[NSString stringWithFormat:@"/Up2Date/%@.%@.%@.%@",_textMonth.text,_textDay.text,_textYear.text,_textMeetingName.text];

您忘记添加下划线。