我有一个视图,有很多选择像checkInDate,checkOutDate(uidatepicker) 和年龄,房间(uipickerView)......
我想使用showActionSheet在点击不同的tableViewCell时显示不同的pickerview
但我有两个问题:
这是主要代码:
- (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];
}
答案 0 :(得分:1)
您可以设置选择器视图的框架。
而不是
age = [[UIPickerView alloc] init];
使用
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:<Your frame>];
或
[picker setFrame:<your frame>];
使用此功能,您可以使用多个选择器视图。
为两者保留一个标识符,以便您可以处理代理。