添加日期选择器以编程方式查看? [英] Adding Date Picker to view programmatically?

查看:153
本文介绍了添加日期选择器以编程方式查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以说明(或指向一个很好的教程)如何以编程方式将日期选择器添加到视图中(即,不使用界面编辑器)?

Can someone illustrate (or point me to a good tutorial) on how to add a Date Picker to a view programmatically (i.e., without using the interface editor)?

推荐答案

这很容易。你可以在几秒钟内完成。

It's very easy man.You can do it in seconds.

只需在your.m文件中使用这些方法......一切就绪

Just use the these methods in your.m file...all is ready

- (void)viewDidLoad {

    CGRect pickerFrame = CGRectMake(0,250,0,0);

    UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
    [myPicker addTarget:self action:@selector(pickerChanged:)               forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:myPicker];
    [myPicker release]; 
}

- (void)pickerChanged:(id)sender
{
    NSLog(@"value: %@",[sender date]);
}

这篇关于添加日期选择器以编程方式查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆