UIPickerView直到滚动才重新加载

Kyl*_*isi 2 xcode objective-c uisegmentedcontrol uipickerview

使用段控件我正在尝试使用新的数据数组重新加载2个UIPickerViews.

我的问题是,直到我在选择器上向上或向下滚动时,新数组才会显示(旧数据一旦离开视图就会消失).我试过使用reloadAllComponents方法没有运气.这是代码的样子:

//Segment Control
-(IBAction)unitType:(id)sender {
    if([sender selectedSegmentIndex]==0){
        NSLog(@"unitType change 1");
        NSLog(@"before values = %@",units);
        [units removeAllObjects];
        [units addObject:@"in"];
        //etc.
        [self.inputUnits reloadAllComponents];
        NSLog(@"current values = %@",units);
    }else {
        NSLog(@"unitType change 2");
        NSLog(@"before values = %@",units);
        [units removeAllObjects];
        [units addObject:@"in^3"];
        //etc.
        [self.inputUnits reloadAllComponents];
        NSLog(@"current values = %@",units);
    }
}
Run Code Online (Sandbox Code Playgroud)

IB有2个UIPickerViews连接到文件的所有者,用于委托和数据源.

Dav*_*ong 5

你还没有联系UIPickerView到你的inputUnits财产.因此,您的调用将-reloadAllComponents被发送到nil,并且当pickerView想要显示新内容(滚动时它会执行)时,事情才会更新.