English 中文(简体)
UIPicker - 初步价值问题
原标题:UIPicker - Initial value problem

我有一个包含数字价值的3个组成部分的UIPicker,这使用户能够用h:mm:ss格式确定时间。 如果我从第一部分中选择这个小时,那么我的核心技术就是这样:10:1(null):(null)。 当用户选择适当的毫米和秒时,可以删除(null)。 但是,如果用户只是想进入10个小时,我想其他数值是00,而不是(null),而使用者不必亲自搬走 pick子。

没有人对此有任何想法?

下面的几部法典涉及时间问题。

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if([pickerView isEqual: routePicker])
    {
        route.text = [[routeArray objectAtIndex:0] valueForKey:@"route_name"];
        return [[routeArray objectAtIndex:row] valueForKey:@"route_name"];
    }
    else if([pickerView isEqual: activityPicker])
    {
        activity.text = [activityArray objectAtIndex:0];
        return [activityArray objectAtIndex:row];
    }
    else if([pickerView isEqual: intensityPicker])
    {
        if ([intensityArray objectAtIndex:row]==@"Low")
            numberIntensity=2;
        else if ([intensityArray objectAtIndex:row]==@"Low-Medium")
            numberIntensity=3.5;
        else if ([intensityArray objectAtIndex:row]==@"Medium")
            numberIntensity=5;
        else if ([intensityArray objectAtIndex:row]==@"Medium-High")
            numberIntensity=6.5;
        else if ([intensityArray objectAtIndex:row]==@"High")
            numberIntensity=8;
        else numberIntensity=0;

        intensity.text = [intensityArray objectAtIndex:0];
        return [intensityArray objectAtIndex:row];
    }
    else if([pickerView isEqual: timePicker])
    {
        switch (component)
        {
            case 0:
                return [hourArray objectAtIndex:row];
                break;
            case 1:
                return [minuteArray objectAtIndex:row];
                break;
            case 2:
                return [secondArray objectAtIndex:row];
                break;
            default:
                return 0;
                break;
        }
    }
    else if([pickerView isEqual: distancePicker])
    {
        switch (component)
        {
            case 0:
                return [distance1Array objectAtIndex:row];
                break;
            case 1:
                return [distance2Array objectAtIndex:row];
                break;
            default:
                return 0;
                break;
        }
    }   
    else 
    {
        return 0;
    }
}



-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if([pickerView isEqual: routePicker])
    {
        route.text = [[routeArray objectAtIndex:row] valueForKey:@"route_name"];
    } 
    else if([pickerView isEqual: timePicker])
    {
        if (component == 0)
        {
            selectedHour = [hourArray objectAtIndex:row];
        } 
        else if (component == 1)
        {
            selectedMinute = [minuteArray objectAtIndex:row];
        } 
        else if (component == 2)
        {
            selectedSecond = [secondArray objectAtIndex:row];
        }
        time.text = [NSString stringWithFormat:@"%@:%@:%@", selectedHour, selectedMinute, selectedSecond];
    }
    else if([pickerView isEqual: distancePicker])
    {
        if (component == 0)
        {
            selectedDistance1 = [distance1Array objectAtIndex:row];
        } 
        else if (component == 1)
        {
            selectedDistance2 = [minuteArray objectAtIndex:row];
        } 
        distance.text = [NSString stringWithFormat:@"%@.%@", selectedDistance1, selectedDistance2];
    }
    else if([pickerView isEqual: activityPicker])
    {
        activity.text = [activityArray objectAtIndex:row];
    }
    else if([pickerView isEqual: intensityPicker])
    {
        intensity.text = [intensityArray objectAtIndex:row];
    }
}
最佳回答

我认为:

time.text = [NSString stringWithFormat:@"%@:%@:%@", selectedHour, selectedMinute, selectedSecond];

可以改为:

time.text = [NSString stringWithFormat:@"%@:%@:%@",
             (selectedHour ? selectedHour : @"00"),
             (selectedMinute ? selectedMinute : @"00"),
             (selectedSecond ? selectedSecond : @"00")];

假设<代码>选择Hour,s selectedMinutes部分当选。 最初都是在本法典外的<代码>nil。 我远离我的马奇,因此,我没有做过试验。

或者,请将<条码>中选编的Hour、<条码>中选编的明文/代码>和<条码>中选编的二次<>>至<条码>00>。

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签