使用操作表单击按钮时,如何将日期显示到文本字段

时间:2014-09-15 05:43:01

标签: ios

按钮点击事件

- (IBAction)datebutton:(id)sender {


    UIActionSheet *actionSheet1=[[UIActionSheet alloc]initWithTitle:@"Birth Date added !!!!!!"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Add Birth Date",@"OK" ,nil];

    [actionSheet1 showInView:self.view];


}


-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
        {

            NSDate  *selected=[_datePicker date];
            NSString *message=[[NSString alloc]initWithFormat:@"date and time like:%@",selected];

            //dateTextField.text=message;


     //UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Date" message:message delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
     //[alert show];
        }
            break;
        case 1:
        {

        }
            break;
            case 2:
        {
             [self.navigationController popViewControllerAnimated:YES];
        }
            break;

    }

1 个答案:

答案 0 :(得分:0)

看看this blog post。它提供category,有助于将日期和字符串转换为反之亦然。您需要根据NSDate解析format对象,然后分配给某些UITextFieldUILabel

修改

您已成功解析了日期,但未将message变量分配给UITextField,您的代码应如下所示:

case 0:
{

    NSDate  *selected=[_datePicker date];
    NSString *message=[[NSString alloc]initWithFormat:@"date and time like:%@",selected];

    // Assign to the control here
    yourTextField.text = message;
}