不显示 UIPickerView 的内容

问题描述

我使用的是UIPickerView,大部分情况下都可以正常使用,但是在iphone11 Pro iOS14.6环境下,UIPickerView的内容不显示。 如下图(上图:正常工作。下图:在iphone11 Pro iOS14.6环境下无法正常工作)

working properly

Not working properly under the environment of 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 (将#修改为@)