0

我有许多选择的视图,例如 checkInDate、checkOutDate (uidatepicker) 和年龄、房间(uipickerView)...

我想在单击不同的 tableViewCell 时使用 showActionSheet 显示不同的pickerview

但我有两个问题:

  1. 如果我使用 checkOutDate.date = nowDate,则 checkInDate 和 theCheckOutDate 不能第二次显示;
  2. 我如何在这个视图中使用多选择器视图?它不应该是多个组件。

这是主要代码:

- (void)viewDidLoad {
    age = [[UIPickerView alloc] init];
    age.showsSelectionIndicator = YES;
    age.delegate = self;
    NSArray *ageData = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];
    self.pickerData = data;

    //room = [[UIPickerView alloc] init];
    //room.showsSelectionIndicator = YES;
    //room.delegate = self;
    //NSArray *roomData = [[NSArray alloc] initWithObjects:@"6", @"7", nil];
    //self.pickerData = roomDate;

//check data
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [[NSDateComponents alloc] init];
    components.day = 1;
    NSDate *now = [NSDate date];
    NSDate *nextDay = [gregorian dateByAddingComponents:components toDate:now options:0];
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    formatter.dateFormat = @"yyyy-MM-dd";
    checkInDateStr = [formatter stringFromDate:nextDay];
    NSDate *dayAfterTom = [gregorian dateByAddingComponents:components toDate:nextDay options:0];
    checkOutDateStr = [formatter stringFromDate:dayAfterTom];

    checkInDate = [[UIDatePicker alloc] init];
    checkInDate.tag = checkInDateTag;
    [checkInDate setMinimumDate:now];
    checkInDate.datePickerMode = UIDatePickerModeDate;
    //checkInDate.date = nextDay;
    checkOutDate = [[UIDatePicker alloc] init];
    checkOutDate.tag = checkOutDateTag;
    [checkOutDate setMinimumDate:nextDay];
    checkOutDate.datePickerMode = UIDatePickerModeDate;
    //checkOutDate.date = dayAfterTom;
}

- (void)showActionSheet:(NSIndexPath *)indexPath withDataPickerTag:(NSInteger *)tag{
    NSString *title = 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 *actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"done", nil];
    [actionSheet showInView:self.view];
    //UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
    //  datePicker.tag = 101;
    //  datePicker.datePickerMode = UIDatePickerModeDate;
    //  NSDate *now = [NSDate date];
    //  [datePicker setDate:now animated:YES];
    if (tag == 201){
        [actionSheet addSubview:checkInDate];
    }else if (tag == 202){
        [actionSheet addSubview:checkOutDate];
    }
}

#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [pickerData count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [pickerData objectAtIndex:row];
}
4

1 回答 1

1

您可以设置选择器视图的框架。

代替

age = [[UIPickerView alloc] init];

利用

UIPickerView *picker = [[UIPickerView alloc] initWithFrame:<Your frame>];

或者

[picker setFrame:<your frame>];

使用它,您可以使用多个选择器视图。

为两者保留一个标识符,以便您可以处理代表。

于 2010-03-08T09:27:13.033 回答