没有调用UIPicker的方法titleForRow

时间:2015-02-25 16:00:22

标签: ios objective-c uipickerview

我想在我的项目中使用UIPickerView,但即使调用了numberOfComponentsInPickerView和numberOfRowsInComponent,我的titleForRow方法也没有被调用。有谁知道该怎么办?

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

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return pickerData.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString *title = [pickerData objectAtIndex:row];
    return title;
}

这些是我的UIPickerView方法,我已经像这样设置了dataSource和delegate:

self.schedulePicker.dataSource = self;
self.schedulePicker.dataSource = self;

我在Xcode 6.1.1中工作,但部署目标是7.1。

感谢任何人的帮助。

1 个答案:

答案 0 :(得分:1)

您已设置UIPickerViewDatasource两次而不是设置UIPickerViewDelegate

更改为:

self.schedulePicker.dataSource = self;
self.schedulePicker.delegate = self;