按钮点击事件
- (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;
}
答案 0 :(得分:0)
看看this blog post。它提供category
,有助于将日期和字符串转换为反之亦然。您需要根据NSDate
解析format
对象,然后分配给某些UITextField
或UILabel
修改强>
您已成功解析了日期,但未将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;
}