我想知道我如何创建一个选择器视图小时,然后我选择的内容出现在标签中....然后把这个小时放在条件(IF)中。??
任何人都可以帮助我吗?
答案 0 :(得分:0)
试试这个: 在.h文件中定义这些变量:
UIPickerView *picker;
NSArray *HOURS_24;
UILabel *hourLabel;
在viewDidLoad中:
HOURS_24=[[NSArray alloc] initWithObjects: @" 8:00", @" 9:00", @" 10:00", @" 11:00",
@" 12:00", @" 13:00", @" 14:00", @" 15:00", @" 16:00", @" 17:00", @" 18:00", nil];
//Add picker in XIB or add it using code like below.
picker=[[UIPickerView alloc]initWithFrame:CGRectMake:(100,100,100,100)];
picker.delegate=self;
[self.view addSubview:picker];
hourLabel=[[UILable alloc]initWithFrame:CGRectMake: (20,100,50,20)];
[self.view addSubview:hourLabel];
hourLabel.text=@"This is hour label";
添加这些功能
#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [HOURS_24 count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [HOURS_24 objectAtIndex:row];
}
实施委托:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
hourLabel.text=[HOURS_24 objectAtIndex:row];
}
答案 1 :(得分:0)
完成此示例项目------- http://www.dosomethinghere.com/wp-content/uploads/2010/11/DatePickerExample.zip
要检查,您可以使用标签的.text,例如if(date label.text == .......) 希望这会有所帮助...