标题说明了这一切,我有一个方法被调用来创建 UIPickerView 并且在与委托方法相同的视图控制器中。视图控制器实现了 UIPickerViewDataSource 和 UIPickerViewDelegate 协议
// ViewController.m
- (void)setUpPickerView{
UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.dataSource = self;
pickerView.delegate = self;
pickerView.showsSelectionIndicator=YES;
self.groupsTextField.inputView = pickerView;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [self.pickerViewData count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return self.pickerViewData[row];
}
我已经看到很多答案,人们说如果 pickerView:numberOfRowsInComponent:component 返回 0 这将停止调用其他委托方法,但是当我设置断点时根本不会调用任何委托方法。
在此先感谢您的帮助!