本文介绍了在点击UITextField时在UIActionSheet中显示UIDatePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建闹钟应用。我想在点击 UITextField 时在 UIActionSheet 中显示 UIDatePicker

I am creating Alarm app. I want to display UIDatePicker in UIActionSheet when tapping on UITextField.

推荐答案

为此,你需要实现 UIActionShetDelegate UITextFieldDelegate
textFieldDidBeginEditing 中,您需要显示以下操作表:

For doing this you need to implement UIActionShetDelegate and UITextFieldDelegateIn the textFieldDidBeginEditing you need to show the action sheet like:

-(void)textFieldDidBeginEditing:(UITextField *)sender
{
  [self showAction];
}
-(void) showAction
{
  UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Pick the date." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil];
  [asheet showInView:[self.view superview]];
  [asheet setFrame:CGRectMake(0, 117, 320, 383)];
  [asheet release];
}

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
  {

    UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];

   //Configure picker...
   [pickerView setMinuteInterval:5];
   [pickerView setTag: kDatePickerTag];

  //Add picker to action sheet
  [actionSheet addSubview:pickerView];

  [pickerView release];

  //Gets an array af all of the subviews of our actionSheet
  NSArray *subviews = [actionSheet subviews];

  [[subviews objectAtIndex:SelectButtonIndex] setFrame:CGRectMake(20, 266, 280, 46)];
  [[subviews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 317, 280, 46)];

}

这篇关于在点击UITextField时在UIActionSheet中显示UIDatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 07:51