0
在我的應用程序我添加文本委託和setBirthDate方法採取日期 和setGender設置性別從選擇器視圖 後用戶選擇出生日期和性別,我試圖將它們發送到數據庫。 當我用NSLog打印值時,它顯示了他選擇的值,但是當我將它發送到數據庫時,它顯示NULL!數據庫從選擇器視圖和日期視圖中接收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 =(空)&的sname =(空)&性別=( null)& [email protected] & mobile_number = 0569327234 & nID =(null)&出生= 2013年10月14日&地點=(空)& schoole_stage = GR &興趣= EXH &消息= gsddgf
另外我使用故事板和i。從3視圖控制器收集的信息我試圖通過數據之間的視圖,但它再次通過(NULL)... ahhhh
您可以將代碼保存到數據庫的位置嗎? – Yan