Xcode iPhone时间选择器

时间:2011-03-24 16:34:03

标签: iphone ios4 uidatepicker

我正在尝试为时间选择器设置一个NSArray类,我想知道我是否可以使用UIDatePicker并只导入NSArray?

这就是我对代码所拥有的:

- (IBAction)showActionTime:(id)sender {
    NSString *title2 = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
    UIActionSheet *actSheet = [[UIActionSheet alloc]
                               initWithTitle:[NSString stringWithFormat:@"%@", title2, NSLocalizedString(@"Please Select A Time", @"")]
                               delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"I've Made My Choice", nil];
    [actSheet showInView:self.view];
    UIPickerView *timePicker = [[[UIPickerView alloc] init] autorelease];
    [timePicker setTag: time1];
    //timePicker.
    [actSheet addSubview:time1];
    [timePicker addTarget:self
                   action:@selector(updateTimeLabel:)
         forControlEvents:UIControlEventValueChanged];
    [actSheet release];
}


- (void)updateTimeLabel:(UIActionSheet *) actSheet{
    NSLog(@"Button Pressed");
    NSArray *times = [[NSArray alloc] initWithObjects:@"8:00-11:00",@"2:00-5:00",nil];
    UIPickerView *timePicker2 = (UIPickerView *) [actSheet viewWithTag:time1];
    [times release];


    //[formatter release];; 
    //UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Date" message:selectedDate delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    //label1.text = msg;
    //[dateFormatter release];

    //[alert show];
    //[alert release];
    //[msg release];
}   

但它甚至没有尝试加载ActionSheet开始。它只是立即崩溃。可能是什么问题?

*更新:

这是我的一个警告:

@implementation AppointmentController和警告是“不完整的实现”

并在这一行:

[timePicker addTarget:self action:@selector(updateTimeLabel)

我收到“节目收到信号:”SIGABRT“

1 个答案:

答案 0 :(得分:0)

Macfan9000,

什么是time1?

为什么要将其添加为子视图?

我猜您的意思是使用[actSheet addSubview:timePicker];