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

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

问题描述

有人可以向编程方式(即不使用界面编辑器)添加日期选择器来说明(或者指向一个好的教程)吗?

解决方案

这很简单,你可以在几秒钟内完成。



只需在你的文件中使用这些方法...都准备好了

   - (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]);
}


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

解决方案

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

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天全站免登陆