Xcode iPhone 时间选择器

发布于 2024-10-25 12:19:20 字数 1861 浏览 6 评论 0原文

我正在尝试为时间选择器设置 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”

I'm trying to set up an NSArray class for a time picker, I was wondering if I could use a UIDatePicker and just import the NSArray?

This is what I have for code:

- (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];
}   

But it doesn't even try to load the ActionSheet to begin with.It just crashes immediately. What could possibly be the problem?

*UPDATE:

Here is one of my warnings:

@implementation AppointmentController and the warning is "Incomplete Implementation"

and on this line:

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

I'm getting "Program received signal: "SIGABRT"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭泣的笑容 2024-11-01 12:19:20

Macfan9000,

time1 是什么?

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

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

Macfan9000,

What is time1?

And why are you adding it as a subview?

My guess is you mean to use [actSheet addSubview:timePicker];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文