0

プログラムで UIDatePicker を作成し、メソッドから選択した値をテキストフィールドに設定しています。しかし、値はテキストフィールドに入らず、ピッカーは隠れていません。誰でも私を助けることができますか?私のコードはここにあります

 datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 245, 320, 270)];
[self.view addSubview:datePicker];
datePicker.hidden=YES;
[datePicker release];
datePicker.datePickerMode = UIDatePickerModeDate;
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy:MMMM:dd"];
self.dobtxt.text = [outputFormatter stringFromDate:self.datePicker.date];
[outputFormatter release];
[DoneBtnDate setBackgroundImage: [UIImage imageNamed: @"OTdone.png"] forState:UIControlStateNormal];
PickerDoneviewDate=[[UIView alloc]initWithFrame:CGRectMake(0,210, 320, 35)];
PickerDoneviewDate.backgroundColor=[UIColor clearColor];
PickerDoneviewDate.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"MFC_tab_01.png"]];
DoneBtnDate = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[DoneBtnDate addTarget:self action:@selector(DatePickerDone:)forControlEvents:UIControlEventTouchDown];
DoneBtnDate.frame = CGRectMake(245,5, 70, 30);
[PickerDoneviewDate addSubview:DoneBtnDate];
[self.view addSubview:PickerDoneviewDate];
PickerDoneviewDate.hidden=YES;
}

   -(void)DatePickerDone:(id)sender
{
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy:MMMM:dd"];

self.dobtxt.text = [outputFormatter stringFromDate:self.datePicker.date];
[datePicker release]; 
[datePicker setHidden:TRUE];

PickerDoneviewDate.hidden=YES;
[outputFormatter release];
}

テキストフィールドを追加するコード

    dobtxt = [[UITextField alloc] initWithFrame:CGRectMake(150, 120, 133, 26)];
    dobtxt.borderStyle = UITextBorderStyleNone;
    dobtxt.background=[UIImage imageNamed: @"textbox_small.png"];
    dobtxt.font = [UIFont fontWithName:@"Arial" size:13];
    dobtxt.delegate = self;
    dobtxt.userInteractionEnabled=YES;
    dobtxt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    [scroll addSubview:dobtxt];
4

1 に答える 1

0

datePicker はプロパティであり、自動解放されます。削除してください

[datePicker release]; 


self.datePicker = [[[UIDatePicker alloc] initWithFrame:CGRectMake(0, 245, 320, 270)] autorelease];
[self.view addSubview:datePicker];
self.datePicker.hidden=YES;
//[datePicker release];
datePicker.datePickerMode = UIDatePickerModeDate;
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy:MMMM:dd"];
self.dobtxt.text = [outputFormatter stringFromDate:self.datePicker.date];
[outputFormatter release];
[DoneBtnDate setBackgroundImage: [UIImage imageNamed: @"OTdone.png"] forState:UIControlStateNormal];
PickerDoneviewDate=[[UIView alloc]initWithFrame:CGRectMake(0,210, 320, 35)];
PickerDoneviewDate.backgroundColor=[UIColor clearColor];
PickerDoneviewDate.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"MFC_tab_01.png"]];
DoneBtnDate = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[DoneBtnDate addTarget:self action:@selector(DatePickerDone:)forControlEvents:UIControlEventTouchDown];
DoneBtnDate.frame = CGRectMake(245,5, 70, 30);
[PickerDoneviewDate addSubview:DoneBtnDate];
[self.view addSubview:PickerDoneviewDate];
 self.PickerDoneviewDate.hidden=YES;
}

-(void)DatePickerDone:(id)sender
{
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy:MMMM:dd"];

self.dobtxt.text = [outputFormatter stringFromDate:self.datePicker.date];
//[datePicker release]; 
[datePicker setHidden:TRUE];

PickerDoneviewDate.hidden=YES;
[outputFormatter release];
}
于 2012-05-24T05:33:41.527 に答える