我开发ipad应用程序,我有一个按钮,我想在点击按钮时出现一个包含datepicker的子视图,做取消。
问题是
当单击“取消”应用程序崩溃时,未识别的选择器发送给实例
时,未显示
我使用以下代码
-(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];
}请给我任何建议
发布于 2011-05-30 10:35:47
错在这条线上
pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,700, 768, 216)];它应该是
pickerView = [[UIDatePicker alloc]initWithFrame:CGRectMake(0,700, 768, 216)];发布于 2011-05-30 09:37:03
您不应该发布您的pickerView和myTab,直到您完成它,从-(IBAction)BirthDatePicker:(id)sender中删除发行版,然后移动到-(void)_Done和-(void)_Cancel。
https://stackoverflow.com/questions/6174508
复制相似问题