我有一个表格视图,它显示我们使用操作表中的日期选择器选择时间的数据。
在此表中查看每一行都有一个带有标签和 uiswitch 按钮的自定义单元格“ReminderCell”
1.自定义单元格 ![在此处输入图像描述][1]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Note: I set the cell's Identifier property in Interface Builder to DemoTableViewCell.
ReminderCell *cell = (ReminderCell *)[tableView dequeueReusableCellWithIdentifier:CellClassName];
if (!cell)
{
NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
//set from action sheet only this row 0
if( indexPath.row == 0 )
{
if(date == nil)
{
date = [NSDate date];
}
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"hh:mm a"];
cell.label.text = [timeFormatter stringFromDate:date];
}
当用户选择一行时,带有日期选择器弹出窗口的操作表
![在此处输入图像描述][3]
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(date == nil)
{
date = [NSDate date];
}
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"hh:mm a"];
//Add Action sheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Done",nil];
// Add date picker to the action sheet
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeTime;
[actionSheet addSubview:datePicker];
[actionSheet showInView:self.navigationController.tabBarController.view];
[actionSheet setBounds:CGRectMake(0,0,320, 550)];
[datePicker setFrame:CGRectMake(0, 138, 320, 216)];
[datePicker release];
[actionSheet release];
}
现在我需要通过从这个日期选择器中选择日期来设置提醒,并在打开时设置。 提前致谢