【发布时间】:2014-07-12 00:27:21
【问题描述】:
我有一个 uipickerview,我正在尝试使用 coredata 数据库中的博士列表填充它。我正在 viewdidload 中加载博士列表,并通过 nslog 语句验证了它们的存在。在验证它们在那里之后,我执行了 reloadallcomponents 并且我的pickerview 显示了适当数量的“?”分数。当我设置断点时,我注意到我的应用程序通过两次获取行数,并返回适当的数字,但 titleforrow 方法从未被调用。有什么想法吗?
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
NSLog(@"there are %d doctors",[self.doctors count]);
return [self.doctors count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSLog(@"Row %d has dr %@",row,[self.doctors objectAtIndex:row]);
return [self.doctors objectAtIndex:row];
}
【问题讨论】:
-
除了
dataSource之外,您是否设置了选择器视图的delegate? -
titleForRow:和numberOfRowsInComponent:/numberOfComponentsInPickerView:不是所有数据源方法吗? -
@nhgrif 你在问我吗?看文档。
-
嗯,好像没有。两个
numberOf方法在datasource中。其他所有内容都在delegate中。 -
我已将类设置为数据源和委托。那应该没问题。对?? @interface DBEPatientVC ()
标签: ios objective-c uipickerview