Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何更改每个组件中的行数_Iphone_Objective C_Uipickerview - Fatal编程技术网

Iphone 如何更改每个组件中的行数

Iphone 如何更改每个组件中的行数,iphone,objective-c,uipickerview,Iphone,Objective C,Uipickerview,如何更改每个组件中的行数 我有这个: - (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return 3; } 但这会改变所有组件的行数 下一个问题是:如何更改第三个组件(如UIDatePicker)中的值:例如:日期(1月)为31天,但(2月)为29/28天。第三个组件必须更改,并且值将在1-29或1-28之间。取决于您的需要。返回不同的号码

如何更改每个组件中的行数 我有这个:

- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
return 3;
}
但这会改变所有组件的行数


下一个问题是:如何更改第三个组件(如UIDatePicker)中的值:例如:日期(1月)为31天,但(2月)为29/28天。第三个组件必须更改,并且值将在1-29或1-28之间。

取决于您的需要。返回不同的号码

- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{

if(CONDITION 1)
return 2;
else if(CONDITION 2)
return 3;
}

这取决于你的需要。返回不同的号码

- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{

if(CONDITION 1)
return 2;
else if(CONDITION 2)
return 3;
}

每个选择器调用
-pickerView:numberOfRowsInComponent:
,并要求它提供每个组件的行数。这个方法被调用了三次,因为有三个组件。因此,您需要为组件返回不同的值。在
组件
变量中会得到一个NSInteger,以指示需要哪个组件:

- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
    switch(component) 
    {
        case 0: // first component has 42 rows
            return 42;
        case 1: // second component has 21 rows
            return 21;
        case 2: // third component has only two rows
            return 2;
    }
}

每个选择器调用
-pickerView:numberOfRowsInComponent:
,并要求它提供每个组件的行数。这个方法被调用了三次,因为有三个组件。因此,您需要为组件返回不同的值。在
组件
变量中会得到一个NSInteger,以指示需要哪个组件:

- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
    switch(component) 
    {
        case 0: // first component has 42 rows
            return 42;
        case 1: // second component has 21 rows
            return 21;
        case 2: // third component has only two rows
            return 2;
    }
}

可以更改方法中每个组件的行数


- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
    switch(component) 
    {
        case 0: // first component has 12 rows for example months
            return 12;
        case 1: // second component has 31 rows for example days

           return 31;
    }
}
关于计算第二个组件中有多少行(天)的第二个问题,您必须保留一个变量来存储选择的月份。根据所选月份,您可以保留一个变量来存储第二个组件中的行数(天)。变量为第1个组件(月)的选择更改时必须更新的天数。然后,您只需按如下方式更改以前的代码:

- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
    switch(component) 
    {
        case 0: // first component has 12 rows for example months
            return 12;
        case 1: // second component to show days            
           return days;
    }
}

希望您能理解…

您可以更改方法中每个组件的行数


- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
    switch(component) 
    {
        case 0: // first component has 12 rows for example months
            return 12;
        case 1: // second component has 31 rows for example days

           return 31;
    }
}
关于计算第二个组件中有多少行(天)的第二个问题,您必须保留一个变量来存储选择的月份。根据所选月份,您可以保留一个变量来存储第二个组件中的行数(天)。变量为第1个组件(月)的选择更改时必须更新的天数。然后,您只需按如下方式更改以前的代码:

- (NSInteger) pickerView:(UIPickerView *)pickerView  numberOfRowsInComponent:(NSInteger)component
{
    switch(component) 
    {
        case 0: // first component has 12 rows for example months
            return 12;
        case 1: // second component to show days            
           return days;
    }
}

希望您能理解…

您能回答我的第一个问题“每个组件中的行数”吗?我不知道您的组件的工作原理。所以,我不知道你放了什么。例如,你有一个数字选择器,你可以把。如果(计数器号>=100)返回3;否则返回2;你能回答我的第一个问题“每个组件中的行数”吗?我不知道你的组件的工作原理。所以,我不知道你放了什么。例如,你有一个数字选择器,你可以把。如果(计数器号>=100)返回3;否则返回2;谢谢比约恩·马尔斯科莱克。。。但是我怎么能有不同价值观的标题呢?工作原理是一样的。实现方法
–pickerView:titleForRow:forComponent:
,再次使用switch语句,但返回所需的标题字符串。也许您希望避免使用
switch
语句,而改用
if
,因为现在您有两个条件要检查(
row
component
)每个行中的值的组件它给我相同的行值我应该怎么做?我建议发布一个新的问题,并给出详细的描述。我不太明白问题是什么。谢谢比约恩·马尔斯科莱克。。。但是我怎么能有不同价值观的标题呢?工作原理是一样的。实现方法
–pickerView:titleForRow:forComponent:
,再次使用switch语句,但返回所需的标题字符串。也许您希望避免使用
switch
语句,而改用
if
,因为现在您有两个条件要检查(
row
component
)每个行中的值的组件它给我相同的行值我应该怎么做?我建议发布一个新的问题,并给出详细的描述。我不太明白问题是什么。谢谢吉普赛人,你能告诉我怎么才能有不同值的标题,如“二月”值为1或“十二月”值为12。你可以保留一个带有月份名称的字符串数组。然后返回字符串。感谢吉普赛人,你能告诉我如何使用不同值的标题,如“二月”值为1或“十二月”值为12。你可以保留一个包含月份名称的字符串数组。然后返回字符串。