uidatepicker问题

时间:2011-05-30 09:32:07

标签: iphone objective-c cocoa-touch ipad

我开发ipad应用程序,我有一个按钮,我想在点击按钮时出现一个包含datepicker的子视图,完成取消

问题在于

  1. 没有出现日期评论
  2. 单击取消时,应用程序崩溃无法识别的选择器发送到实例
  3. 我使用以下代码

    -(IBAction)BirthDatePicker:(id)sender{
        if(! ISPicker) {
    
            if( self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
            {
                pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,700, 768, 216)];
                mytab = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 656, 768, 44)];
    
    
            }
            else {
                pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,439, 1024, 216)];
                mytab = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 395, 1024, 44)];
    
    
            }
    
    
            pickerView.alpha=0.0;
            mytab.alpha=0.0;
    
            //pickerView.showsSelectionIndicator = YES;
            [self.view addSubview:pickerView];
            [self.view bringSubviewToFront:pickerView]; 
    
            mytab.tintColor=[UIColor blackColor];
    
            UIBarButtonItem * bt1=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(_Done)];
            UIBarButtonItem * bt2=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(_cancel)];
            UIBarButtonItem * flx=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    
            NSArray *arr=[[NSArray alloc] initWithObjects:flx,bt1,bt2,nil];
            [mytab setItems:arr];
            [self.view addSubview:mytab];
    
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.3];
            pickerView.alpha=1.0;
            mytab.alpha=1.0;
            [UIView commitAnimations];
    
            [pickerView release];
            [mytab release];
            [bt1 release];
            [flx release];
            [arr release];
    
            ISPicker = true ;
        }
    }
    
    -(void)_Done{
    
        ISPicker  = false ;
    
        NSDate * selected = [pickerView date];
        NSString * date = [selected description];
        DateLabel.text = date;
    
    }
    
    -(void)_Cancel{ 
    
        ISPicker  = false ;
        //// Release the view 
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.3];
        pickerView.alpha=0.0;
        mytab.alpha=0.0;
    
        [UIView commitAnimations];
    }
    

    请提出任何建议

2 个答案:

答案 0 :(得分:0)

在完成之前,您不应该发布{{1and1}},从 - pickerView移除版本并移至myTab(IBAction)BirthDatePicker:(id)sender

答案 1 :(得分:0)

错误就在这一行

pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,700, 768, 216)];

应该是

pickerView = [[UIDatePicker alloc]initWithFrame:CGRectMake(0,700, 768, 216)];