0

在我的应用程序中,我添加了文本委托和 setBirthDate 方法来获取日期和 setGender 以在用户选择出生日期和性别后从选择器视图中设置性别,我试图将它们发送到数据库。当我用 NSLog 打印值时,它显示了他选择的值,但是当我将它发送到数据库时,它显示为 NULL !

这是我的代码

-(void)setBirthDate{
    actionsheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil     destructiveButtonTitle:nil otherButtonTitles:nil];
    [actionsheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

    CGRect pickframe= CGRectMake(0, 44, 0, 0);
    UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:pickframe];
    [picker setDatePickerMode:UIDatePickerModeDate];

    [actionsheet addSubview:picker];

    UIToolbar *controlToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, actionsheet.bounds.size.width, 44)];
    [controlToolBar setBarStyle:UIBarStyleBlack];
    [controlToolBar sizeToFit];

    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Set" style:UIBarButtonItemStyleDone target:self action:@selector(dissmisBirthDate)];
    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDateSet)];

    [controlToolBar setItems:[NSArray arrayWithObjects:space,setButton,cancel, nil] animated:NO];

    [actionsheet addSubview:controlToolBar];
    [actionsheet showInView:self.view];
    [actionsheet setBounds:CGRectMake(0, 0, 320, 485)];
    check5=TRUE;
    [self ShowGeneral];
}

-(void)dissmisBirthDate
{
    NSArray *listView = [actionsheet subviews];

    for (UIView *subView in listView) {
        if ([subView isKindOfClass:[UIDatePicker class]]) {
            BirthDate = [(UIDatePicker *)subView date];
        }
    }
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [BirthDateTimeText setText:[dateFormatter stringFromDate:BirthDate]];
    [actionsheet dismissWithClickedButtonIndex:1 animated:YES];
}

-(void)cancelDateSet
{
    [actionsheet dismissWithClickedButtonIndex:1 animated:YES];
}

-(void)GenderPickerView
{
    genderArrayTime =[[NSMutableArray alloc]initWithObjects:@"ذكر",@"انثى",nil];
    actionsheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    [actionsheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    GenderPickerTime = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 485)];
    [actionsheet addSubview:GenderPickerTime];
    GenderPickerTime.delegate = self;
    GenderPickerTime.showsSelectionIndicator = YES;

    UIToolbar *controlToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, actionsheet.bounds.size.width, 44)];
    [controlToolBar setBarStyle:UIBarStyleBlack];
    [controlToolBar sizeToFit];

    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(cancelPickerSet)];

    [controlToolBar setItems:[NSArray arrayWithObjects:space,cancel, nil] animated:NO];
    [actionsheet addSubview:controlToolBar];
    [actionsheet showInView:self.view];
    [actionsheet setBounds:CGRectMake(0, 0, 320, 485)];
    [GenderPickerTime selectRow:0 inComponent:0 animated:YES];
    genderTextTime.text = [NSString stringWithFormat:@"%@",[genderArrayTime objectAtIndex:0]];
    gender = [NSString stringWithFormat:@"%@",genderTextTime.text];
    NSLog(@"%@",gender);
    check4=TRUE;
    [self ShowPersonal];
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView == GenderPickerTime) {
        return 2;
    }
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView == GenderPickerTime) {
        genderTextTime.text = [NSString stringWithFormat:@"%@",[genderArrayTime objectAtIndex:row]];
    }
} 

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (pickerView == GenderPickerTime) {
        return [genderArrayTime objectAtIndex:row];
    }
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
  if ([textField isEqual:genderTextTime]) {
    [self GenderPickerView];
  }
}

这里数据库代码:

NSString *post =[[NSString alloc] initWithFormat:@"fname=%@&sname=%@&gender=%@&email=%@&mobile_number=%@&nID=%@&birth=%s&place=%@&schoole_stage=%s&interest=%s&message=%s",FirstNameTextTime.text, LastNameTextTime.text , gender , EmailTextTime.text , PhoneTextTime.text , IdentityNumberTextTime.text, BirthDateTimeText.text , LivingPlaceTextTime.text , "gr","exh","gsddgf"];
NSData *dataURL = [post dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:@"http://....?"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:dataURL];

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@",strResult);

这就是我得到的

fname=(null)&sname=(null)&gender=(null)&email=ali@h.com&mobile_number=0569327234&nID=(null)&birth=2013-10-14&place=(null)&schoole_stage=gr&interest=exh&message=gsddgf

此外,我正在使用 Storyboard 和我从 3 个视图控制器收集的信息,我试图在视图之间传递数据,但它再次传递(NULL)...... ahhhh

4

1 回答 1

1

我解决了不是来自选择器的问题,它发生是因为当我从视图移动到另一个视图时,我需要传递数据。

于 2013-07-19T23:01:38.357 回答