我正在处理用户点击文本字段时显示的选择器视图。有多个文本字段和选择器视图 我能够完成numberOfRowsInComponent但不能完成numberOfRowsInSection。
这是代码:
-(NSInteger)pickerView:(UIPickerView *) pickerView numberOfRowsInComponent:(NSInteger)component {
NSUInteger count = 0;
if (self.schoolPicker) {
count = [self.infoLibrary.school count];
}
if (self.majorPicker) {
count = [self.infoLibrary.major count];
}
if (self.classPicker) {
count = [self.infoLibrary.classPicker count];
}
if (self.nationalityPicker) {
count = [self.infoLibrary.nationality count];
}
if (self.commuterPicker) {
count = [self.infoLibrary.commuter count];
}
if (self.honorsPicker) {
count = [self.infoLibrary.honors count];
}
if (self.varsityAthletePicker) {
count = [self.infoLibrary.varsityAthlete count];
}
return count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *count = 0;
if (self.schoolPicker) {
count = [self.infoLibrary.school objectAtIndex:row];
}
if (self.majorPicker) {
count = [self.infoLibrary.major objectAtIndex:row];
}
if (self.classPicker) {
count = [self.infoLibrary.classPicker objectAtIndex:row];
}
if (self.nationalityPicker) {
count = [self.infoLibrary.nationality objectAtIndex:row];
}
if (self.commuterPicker) {
count = [self.infoLibrary.commuter objectAtIndex:row];
}
if (self.honorsPicker) {
count = [self.infoLibrary.honors objectAtIndex:row];
}
if (self.varsityAthletePicker) {
count = [self.infoLibrary.varsityAthlete objectAtIndex:row];
}
return count;
}
答案 0 :(得分:0)
我对你的问题有点困惑,因为numberOfRowsInSection:是一个UITableViewDataSource的方法,而不是UIPickerViewDataSource。也就是说,您发布的代码存在一致的问题。在您的方法中,您似乎正在测试它所在的选择器视图,例如,检查:
if (self.schoolPicker) { }
...仅检查该选择器视图是否存在,而不是是否是为其调用该方法的视图。
您想要检查:
if (pickerView==self.schoolPicker) { }