【问题标题】:Adding values to UIDatePicker向 UIDatePicker 添加值
【发布时间】:2011-10-24 18:20:35
【问题描述】:

我需要将项目添加到 UIDatePicker,而不是添加日期:

我需要添加一个姓名列表(例如,“James”)。我该怎么做?

【问题讨论】:

    标签: iphone objective-c ios cocoa-touch uidatepicker


    【解决方案1】:

    只需使用UIPickerView

     UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
     myPickerView.delegate = self
     myPickerView.showsSelectionIndicator = YES;
     [self.view addSubview:myPickerView]; 
    
      - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
      {
         return 1;
      }  
      - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
     {   
          return 1;
     }
    
      - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
      {
         NSString *string = [NSString stringWithString:@"Jack"];
         return string;
       }  
    

    编辑:1

    - (NSInteger)selectedRowInComponent:(NSInteger)component
    {
          //Returns the index of the selected row in a given component.
          NSLog(@"%d",component);
    }
    

    【讨论】:

    • 我可以使用- (NSInteger)selectedRowInComponent:(NSInteger)component 方法来选择行吗?如果是这样,方法体会是什么样子。我只需要NSLog 选择的值。请帮忙
    【解决方案2】:

    检查以下内容,

        UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 250)];
        pickerView.delegate = self;
        pickerView.dataSource = self;
        pickerView.showsSelectionIndicator = YES;
        pickerView.opaque = NO;
        [customPickerView addSubview:pickerView];
    
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
    {
        return 1;
    }
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
    {
        return 10;
    }
     - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    ILabel* tView = (UILabel*)view;
    tView.text =  [arrList objectAtIndex:row];
    }
    - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
          //When ever picker view cell is pressed.
          //Write ur logic
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多