gpt4 book ai didi

ios - UIPickerView 不在选择器中显示数据但在 nslog 中显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:44 26 4
gpt4 key购买 nike

问题是选择器没有显示任何数据,但当我在 nslog 中滚动空的选择器 View 时,数据存在于后台,它显示了数据。所以数据正在填充但不显示在 uipickerview 中。提前致谢

代码如下在 .h 文件中我声明了

UIPickerView *picker;

.m 文件

picker = [
[UIPickerView alloc] initWithFrame: CGRectMake(0, 100, 320, 0)];

[picker setDataSource: self];
[picker setDelegate: self];

picker.showsSelectionIndicator = YES;

peoplearray = [
[NSArray alloc] initWithObjects: @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", nil];

timearray = [
[NSArray alloc] initWithObjects: @"12:00 AM", @"12:30 AM", @"1:00 AM", @"1:30 AM", @"2:00 AM", @"2:30 AM", @"3:00 AM", @"3:30 AM", @"4:00 AM", @"4:30 AM", @"5:00 AM", @"5:30 AM", @"6:00 AM", @"6:30 AM", @"7:00 AM", @"7:30 AM", @"8:00 AM", @"8:30 AM", @"9:00 AM", @"9:30 AM", @"10:00 AM", @"10:30 AM", @"11:00 AM", @"11:30 AM", @"12:00 PM", @"12:30 PM", @"1:00 PM", @"1:30 PM", @"2:00 PM", @"2:30 PM", @"3:00 PM", @"3:30 PM", @"4:00 PM", @"4:30 PM", @"5:00 PM", @"5:30 PM", @"6:00 PM", @"6:30 PM", @"7:00 PM", @"7:30 PM", @"8:00 PM", @"8:30 PM", @"9:00 PM", @"9:30 PM", @"10:00 PM", @"10:30 PM", @"11:00 PM", @"11:30 PM", nil];

类似的是日期数组。

-(NSInteger) numberOfComponentsInPickerView: (UIPickerView * ) pickerView {
return 4;
}



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

if (component == 0) {
return [peoplearray count];
} else if (component == 1) {
return [datearray count];
} else if (component == 2)

{
return [timearray count];
} else if (component == 3)

{
return [timearray count];
}

return 0;
}

-(NSString * ) pickerView: (UIPickerView * ) pickerView titleForRow: (NSInteger) row forComponent: (NSInteger) component {

if (component == 0)

{
return [peoplearray objectAtIndex: row];
} else if (component == 1)

{
return [datearray objectAtIndex: row];
} else if (component == 2)

{
return [timearray objectAtIndex: row];
} else if (component == 3)

{

return [timearray objectAtIndex: row];
}

return 0;

}

- (CGFloat) pickerView: (UIPickerView * ) pickerView widthForComponent: (NSInteger) component {
switch (component) {

case 0:

return 35;

case 1:

return 100;

case 2:

return 80;

case 3:

return 80;
}

return 0;
}

- (UIView * ) pickerView: (UIPickerView * ) pickerView viewForRow: (NSInteger) row forComponent: (NSInteger) component reusingView: (UIView * ) view {

UILabel * label = [
[UILabel alloc] initWithFrame: CGRectMake(0, 0, 300, 37)];

if (component == 0)

{
label.text = [peoplearray objectAtIndex: row];

} else if (component == 1)

{
label.text = [datearray objectAtIndex: row];
} else if (component == 2)

{
label.text = [timearray objectAtIndex: row];

} else if (component == 3)

{
label.text = [timearray objectAtIndex: row];
}

label.backgroundColor = [UIColor clearColor];

return label;

}

最佳答案

问题是

- (UIView * ) pickerView: (UIPickerView * ) pickerView viewForRow: (NSInteger) row forComponent: (NSInteger) component reusingView: (UIView * ) view 

如果您删除该部分,它会正常显示。

希望对您有所帮助。

我也在寻找根本原因。如果我得到更多信息,我会更新答案。

////////////////

我找到了原因。将 UILabel 初始化部分更改为

UILabel *label = [[UILabel alloc] init];

会好的。

关于ios - UIPickerView 不在选择器中显示数据但在 nslog 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21159906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com