我有UITableView
并且有三个静态单元格。对于第三个UITableViewCell
(indexPath.row == 2)
,我使用了一个单独的tableviewcell类,因为我想在该单元格中使用日期选择器。所以现在我想要的是:
这是我的UITableViewController
(静态表格视图)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = [flightItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (indexPath.row == 0) {
NSString *defaultText = @"Please select a port";
NSString *selectedText = [[NSUserDefaults standardUserDefaults] objectForKey:@"st"];
if (selectedText) {
defaultText = selectedText;
}
cell.detailTextLabel.text = defaultText;
}
if (indexPath.row == 2) {
DeparturedateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.departureDatepicker.transform = CGAffineTransformMakeScale(0.4, 0.4);
cell.departureDatepicker.frame = CGRectMake(0, 50, 200, 162);
}
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIToolbar *forblurEffect = [[UIToolbar alloc] initWithFrame:CGRectZero];
cell.backgroundView = forblurEffect;
return cell;
}
这是我的UITableViewCell
课程(我用于UITableView
中的第三个单元格)
@interface DeparturedateTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIDatePicker *departureDatepicker;
@end
答案 0 :(得分:0)
试试这个:
在DeparturedateTableViewCell.m
中departureDatepicker.minimumDate=[NSDate Date];
[departureDatepicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
- (void)dateChanged:(id)sender
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd MMM yy"];
NSString *selecttime = [dateFormatter stringFromDate:departureDatepicker.date];
NSLog(@"%@", selecttime);
}
答案 1 :(得分:0)
首先,您需要为DatePicker设置IBOutLet(作为datePicker)。 现在编码为: NSDate * date = self.departureDatepicker.date;
用于禁用之前的日期
- (void)viewDidLoad {departureDatepicker .minimumDate = [NSDate date];
OR
[departureDatepicker setMinimumDate: [NSDate date]];
}
将以下行放在viewDidLoad
中 [departureDatepicker addTarget:self action:@selector(startTimePickerChanged:) forControlEvents:UIControlEventValueChanged];
then add this method,
- (IBAction)startTimePickerChanged:(id)sender
{
NSLog(@“Date value is %@“, departureDatepicker.date);
}