UIPickerView 未连接到数据源

发布于 2024-11-16 11:06:53 字数 1009 浏览 2 评论 0原文

所以我的 UIPickerView 没有连接到数据源。我不知道为什么。

我使用 UIPickerViewDelegateUIPickerViewDataSource 创建一个文件,并正确执行在点击文本字段时引入 UIPickerView 的过程。

pickerView 可以工作,但不显示任何组件。我已经实现了

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

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component 



- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 


- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

知道为什么 pickerView 没有连接到 DataSource 吗?我还在所有这些方法中尝试了 NSLogging。 // 不打印

我也设置了

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

So my UIPickerView does not get connected to the DataSource. I Have no idea WHY.

I create a file with UIPickerViewDelegate and UIPickerViewDataSource, and properly do the procedure for bringing a UIPickerView on tapping a textField.

The pickerView works , but does not show any component. I have implemented

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

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component 



- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 


- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

Any idea why the pickerView is not getting connected to the DataSource ? I also tried NSLogging inside all these methods. // Does not print

I had also set

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

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

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

发布评论

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

评论(2

蓝眸 2024-11-23 11:06:53

在 cellForRowAtIndexPath 中,您设置 packSizePopPickerView 的 dataSource/delegate,然后将 packSizePopPickerView 分配/初始化到新的 UIPickerView。新的 UIPickerView 不再具有其委托/数据源集。

这是错误的:

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

试试这个:

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

In cellForRowAtIndexPath, you're setting packSizePopPickerView's dataSource/delegate, and THEN allocating/initializing packSizePopPickerView to a new UIPickerView. The NEW UIPickerView no longer has its delegate/dataSource set.

This is WRONG:

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

Try this:

packSizePopPickerView = [[UIPickerView alloc] init];
packSizePopPickerView.delegate = self;
packSizePopPickerView.dataSource = self;
烂人 2024-11-23 11:06:53

您需要明确告诉选择器其数据源和委托是什么。

myPicker.delegate = someController;
myPicker.datasource = someController;

You need to explicitly tell the picker what its data sources and delegates are.

myPicker.delegate = someController;
myPicker.datasource = someController;

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