gpt4 book ai didi

iphone - 如何将 UIPickerView 重置为索引 :0, iPhone

转载 作者:行者123 更新时间:2023-12-03 18:31:10 24 4
gpt4 key购买 nike

我正在尝试在单击按钮时重置UIPickerView。我的 pickerview id 是在运行时创建的,我已经设置了委托(delegate)。经过谷歌搜索,我发现

[pickerView reloadAllComponents];

但这会使我的应用程序每次到达此处时都会崩溃。

索引 0 处的对象是“从列表中选择”,然后是项目。单击提交按钮时,我希望“从列表中选择”应保留在标签顶部(所选索引:0)。

这是我的代码

ViewDidload

pickerView = [[UIPickerView alloc] init];
pickerView.delegate = self;
pickerView.dataSource = self;

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


// Total rows in our component.
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [nameArray count];
}

// Display each row's data.
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [nameArray objectAtIndex: row];
}

// Do something with the selected row.

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
dlbl.hidden=YES;
NSLog(@"You selected this: %@", [nameArray objectAtIndex: row]);
[btnSelectDesigner setTitle:[nameArray objectAtIndex: row] forState:UIControlStateNormal];

}

并且,单击按钮时:

-(IBAction)btnSubmitClicked:(id)sender{
[pickerView reloadAllComponents];
}

知道我做错了什么吗?

谢谢

最佳答案

[picker reloadAllComponents];
[picker selectRow:0 inComponent:0 animated:YES];

关于iphone - 如何将 UIPickerView 重置为索引 :0, iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11191062/

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