PickerView准备捕获时间,循环滚动demo

最重要的下面几行代码
- (void) clickRightBarItem
{
    NSInteger row0 = [m_pickerSetupAlarmDate selectedRowInComponent:0];
    NSInteger row1 = [m_pickerSetupAlarmDate selectedRowInComponent:1];
    NSInteger row3 = [m_pickerSetupAlarmDate selectedRowInComponent:3];
    NSInteger row4 = [m_pickerSetupAlarmDate selectedRowInComponent:4];
    
    nRow0 = row0;
    nRow1 = row1;
    nRow2 = row3;
    nRow3 = row4;
    
    NSString *strDate = [NSString stringWithFormat:@"%@:%@-%@:%@    ",
                         [m_mutArrHours objectAtIndex:row0],
                         [m_mutArrMinute objectAtIndex:row1],
                         [m_mutArrHours objectAtIndex:row3],
                         [m_mutArrMinute objectAtIndex:row4]];
    [self saveAlremDate:strDate];
    [m_delegateCreateAlram alermInfoSaveIsCompleteReloadData];
    [self.navigationController popViewControllerAnimated:YES];
}


//一下可忽略不计
//我的picker有4组,定义4个用来存索引,保证取消后点击仍然之前数据
@interface CreateAlramDateViewController ()
{
    //用来记录pickerView数据
    NSInteger nRow0;
    NSInteger nRow1;
    NSInteger nRow2;
    NSInteger nRow3;
}
UIPickerView *pickViewAlermDate = [[UIPickerView alloc] initWithFrame:m_cgRectPickerView];
    self.m_pickerSetupAlarmDate = pickViewAlermDate;
    [pickViewAlermDate release];
    m_pickerSetupAlarmDate.delegate = self;
    m_pickerSetupAlarmDate.dataSource = self;
    m_pickerSetupAlarmDate.showsSelectionIndicator = YES;

#pragma mark pickview delegate
//组件数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 5;
}
//每个组件的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0 || component == 3)
    {
        return 24;
    }
    else if(component == 2)
    {
        return 1;
    }
    else
    {
        return 60;
    }
}
//初始化每个组件每一行数据
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0 || component == 3)
    {
        return [m_mutArrHours objectAtIndex:row];
    }
    else if(component == 2)
    {
        return @"-----";
    }
    else
    {
        return [m_mutArrMinute objectAtIndex:row];
    }
    
}
//选中picker cell,save ArrayIndex
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"row1:%d", row);
    
    row = [pickerView selectedRowInComponent:component];
    
    NSLog(@"row2:%d", row);
}

你可能感兴趣的:(view)