0

我想知道如何创建选择器视图小时,然后我选择的内容出现在标签中....然后将这个小时置于条件(IF)中。??

谁能帮我?

4

2 回答 2

0

浏览这个示例项目------- http://www.dosomethinghere.com/wp-content/uploads/2010/11/DatePickerExample.zip

检查你可以使用标签的 .text 例如 if(date label.text==.......) 希望这会有所帮助......

于 2013-04-08T04:41:04.260 回答
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];
}
于 2013-04-08T04:09:32.853 回答