uipickerview选择值时



所以我实现了一个pickerview,当我选择一些值时,一切正常,但是如果我不选择任何东西

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated

未调用。我想要如果用户不选择一个值,则选择第一个值。

所以我实现了:

-(void)viewDidAppear:(BOOL)animated
{
    [pickerView selectRow:0 inComponent:0 animated:YES];
}

但行不通。为什么选择selectrow:incomponent:在此之后调用方法?

启动时要调用一个新功能。如果您希望在启动应用程序时读取代码输入,则需要将其放在ViewDidload

- (void)viewDidLoad
{
[super viewDidLoad];
[updateWheel];
{
    [super viewDidLoad];
    }
 #Pragma Mark pickerWheel Delegate
- (void)updateWheel
{NSString *wheel1 = [wheel1 objectAtIndex:[picker selectedRowInComponent:0]];
aLabelUWantToHaveOutputIn.text = wheel1; 
} //Whatever code you want to happen

如果这无济于事,请查看使用一些相同机制的项目。http://pastebin.com/wlgq3jvv

    [pickerView selectRow:0 inComponent:0 animated:YES];

它不会调用委托功能。它将仅将指定的行滚动到中心。

最新更新