如何解决不显示 UIPickerView 的内容
我使用的是UIPickerView,大部分情况下都可以正常使用,但是在iphone11 Pro iOS14.6环境下,UIPickerView的内容不显示。 如下图(上图:正常工作。下图:在iphone11 Pro iOS14.6环境下无法正常工作)
我的Objective-c代码如下。
NSMutableArray *years,*months,*days;
NSDateComponents* components;
@property (weak,nonatomic) IBOutlet UIPickerView *myBitrhday;
- (void)viewDidLoad
{
NSDate *today = [NSDate date];
NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:today];
NSInteger todayYear = components.year;
NSInteger todayMonth = components.month;
NSInteger todayDay = components.day;
self.myBitrhday.delegate = self;
self.myBitrhday.backgroundColor = [UIColor whiteColor];
years = [[NSMutableArray alloc] initWithCapacity:(LAST_YEAR-FirsT_YEAR)];
for (int i = FirsT_YEAR; i <= LAST_YEAR; i++) {
[years addobject:[Nsstring stringWithFormat:@"%d年",i]];
}
months = [[NSMutableArray alloc] initWithCapacity:12];
for (int i = 1; i <= 12; i++) {
[months addobject:[Nsstring stringWithFormat:@"%d月",i]];
}
days = [[NSMutableArray alloc] initWithCapacity:31];
for (int i = 1; i <= 31; i++) {
[days addobject:[Nsstring stringWithFormat:@"%d日",i]];
}
NSInteger rowOfTodayYear = todayYear-FirsT_YEAR;
NSInteger rowOfTodayMonth = todayMonth-1;
NSInteger rowOfTodayDay = todayDay-1;
[self.myBitrhday selectRow:rowOfTodayYear inComponent:0 animated:YES];
[self.myBitrhday selectRow:rowOfTodayMonth inComponent:1 animated:YES];
[self.myBitrhday selectRow:rowOfTodayDay inComponent:2 animated:YES];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
switch (component) {
case 0:
return [years count];
case 1:
return [months count];
case 2:
return [days count];
}
return 0;
}
- (Nsstring *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (component) {
case 0:
return [years objectAtIndex:row];
case 1:
return [months objectAtIndex:row];
case 2:
return [days objectAtIndex:row];
}
return nil;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
rowOfYear = (int)[pickerView selectedRowInComponent:0];
rowOfMonth = (int)[pickerView selectedRowInComponent:1];
rowOfDay = (int)[pickerView selectedRowInComponent:2];
}
你能告诉我有什么问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。