アクションシートの日付ピッカーを使用して時間を選択したデータを表示するテーブルビューがあります。
この表では、ラベルと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];
}
次に、この日付ピッカーから日付を選択してリマインダーを設定し、スイッチをオンにしたときにオンに設定する必要があります。 前もって感謝します