UIPickerView 未连接到数据源
所以我的 UIPickerView 没有连接到数据源。我不知道为什么。
我使用 UIPickerViewDelegate
和 UIPickerViewDataSource
创建一个文件,并正确执行在点击文本字段时引入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 cellForRowAtIndexPath 中,您设置 packSizePopPickerView 的 dataSource/delegate,然后将 packSizePopPickerView 分配/初始化到新的 UIPickerView。新的 UIPickerView 不再具有其委托/数据源集。
这是错误的:
试试这个:
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:
Try this:
您需要明确告诉选择器其数据源和委托是什么。
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;