OGeek|极客世界-中国程序员成长平台

标题: ios - 如何显示来自不同类的 datepicker 方法调用? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:42
标题: ios - 如何显示来自不同类的 datepicker 方法调用?

我正在我的 View Controller 类中创建自定义日期选择器。然后我需要另一个 View Controller 类中的日期选择器。所以我想创建任何 View Controller 类都可以使用并显示日期的通用日期选择器。那么我该如何使用它。请分享代码。

我使用这个代码:

 actionSheet = [[UIActionSheet alloc] initWithTitle"Date" delegate:self
                                      cancelButtonTitle:nil
                                 destructiveButtonTitle:nil
                                      otherButtonTitles:nil];
    [actionSheet setBackgroundColor:[UIColor grayColor ]];
    [actionSheet setFrame:CGRectMake(0, 470, 375, 200)];
    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake ( 0, 10, 300, 100)];
    dateFormatter = [[NSDateFormatter alloc] init];
    datePicker.datePickerMode = UIDatePickerModeDate;
    [dateFormatter setDateFormat"MM/dd/yyyy"];
    [datePicker addTarget:self actionselector(dateChanged) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:datePicker];
    UIToolbar *toolbarPicker = [[UIToolbar alloc] init];
    toolbarPicker.backgroundColor=[UIColor grayColor];
    // toolbarPicker.barStyle=UIBarStyleBlackOpaque;
    [toolbarPicker sizeToFit];
    NSMutableArray *itemsBar = [[NSMutableArray alloc] init];
    //calls DoneClicked


    UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self actionselector(doneClicked)];
    [itemsBar addObject:btnDone];
    [toolbarPicker setItems:itemsBar animated:YES];
    [actionSheet addSubview:toolbarPicker];
    [self.view addSubview:actionSheet];
}

-(IBAction)dateChanged{
        self.dateEntry.text = [dateFormatter stringFromDate:[datePicker date]];
}


-(IBAction)doneClicked{
    [actionSheet removeFromSuperview];
    self.dateEntry.userInteractionEnabled = YES;
}



Best Answer-推荐答案


创建 UIView/NSObject 的自定义类,在那里添加您的逻辑,然后实现委托(delegate)设计模式来管理它。

如果您需要对此进行进一步说明,请告诉我。

关于ios - 如何显示来自不同类的 datepicker 方法调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30611064/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4