gpt4 book ai didi

ios - 数据库从选择器 View 和日期 View 接收 NULL

转载 作者:行者123 更新时间:2023-11-29 03:46:53 26 4
gpt4 key购买 nike

在我的应用程序中,我添加了文本委托(delegate)和 setBirthDate 方法来获取日期和 setGender 从选择器 View 设置性别用户选择出生日期和性别后,我尝试将它们发送到数据库。当我用 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 View Controller 收集的信息,我尝试在 View 之间传递数据,但它再次传递(NULL)...啊啊

最佳答案

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

关于ios - 数据库从选择器 View 和日期 View 接收 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17638949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com