UIPickerView 重新加载组件不工作

发布于 2024-12-01 03:31:36 字数 549 浏览 2 评论 0原文

我正在制作一个使用选择器视图的应用程序。当应用程序加载时,选择器视图将获得初始选项。然后,我希望通过更改委托中使用的数组,然后在按下按钮触发的 IBAction 中调用 reloadcomponent 方法来更改这些选项。当我这样做时,什么也没有发生。最初的选择仍然存在。 Delegate 和 dateSource 均设置为文件所有者。任何帮助或建议表示赞赏。下面是 IBAction 中使用的代码(NSLog 显示数组已正确更改):

NSArray *myArray = [[NSArray alloc] initWithObjects:@"Elec Beat 1",@"Elec Beat 2",@"Elec Beat 3",@"Elec Beat 4",@"Elec Beat 5",nil];

[pickerChoices removeAllObjects];
[PickerChoices addObjectsFromArray:myArray];
[pickerView reloadComponent:0];
packSelect = 1;

NSLog(@"%@",pickerChoices);

Im making an app that uses a picker view. When the app loads, the picker view is given initial options. I then wish to change these options by changing the array used in the delegate and then calling the reloadcomponent method in an IBAction triggered by a button press. When i do this, nothing happens. The initial choices are still there. Delegate and dateSource are both set to files owner. Any help or suggestion is appreciated. Below is the code used in the IBAction (the NSLog shows that the array is getting changed correctly):

NSArray *myArray = [[NSArray alloc] initWithObjects:@"Elec Beat 1",@"Elec Beat 2",@"Elec Beat 3",@"Elec Beat 4",@"Elec Beat 5",nil];

[pickerChoices removeAllObjects];
[PickerChoices addObjectsFromArray:myArray];
[pickerView reloadComponent:0];
packSelect = 1;

NSLog(@"%@",pickerChoices);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧街凉风 2024-12-08 03:31:36

你实现了 UIPickerViewDelegate 和 UIPickerDataSource 的方法吗?

Have you implemented methods of UIPickerViewDelegate and UIPickerDataSource?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文