【问题标题】:PickerView hour and show in a LabelPickerView 小时并显示在标签中
【发布时间】:2013-04-08 01:44:00
【问题描述】:

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

谁能帮帮我?

【问题讨论】:

  • 您能否详细说明您已经尝试过的内容以及您可能收到的任何错误。谢谢
  • 仅使用xcode 标签来回答有关 IDE 本身的问题。谢谢!

标签: ios uilabel uipickerview


【解决方案1】:

试试这个: 在 .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];
}

【讨论】:

    【解决方案2】:

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

    为了检查,您可以使用标签的 .text,例如如果(日期标签。文本==.......) 希望这会有所帮助...

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      相关资源
      最近更新 更多