我已经制作了4个pickerviews,每个有15个对象,我实现了所有委托方法。在组件数量上返回1,行数也是正确的,但是对于行方法行总是0并且pickerview没有显示。帮助我找到错误的地方。 这是我的代码
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
NSLog(@"In Number Of Components Method\n");
int numberOfComponents = 1;
return numberOfComponents;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent(NSInteger)component {
NSMutableArray* keysArray = [[NSMutableArray alloc] init];
NSMutableArray* valuesArray = [[NSMutableArray alloc]init];
DBManager* dbManger = [[DBManager alloc] init];
//companyName,city,category,postalCode
NSInteger count = 0;
switch (pickerView.tag) {
case 0:
if (![selectBusinessTextField.text isEqualToString:@""]) {
[keysArray addObject:@"category"];
[valuesArray addObject:selectBusinessTextField.text];
}
if (![selectCityTextField.text isEqualToString:@""]) {
[keysArray addObject:@"city"];
[valuesArray addObject:selectCityTextField.text];
}
if (![selectPostalCodeTextField.text isEqualToString:@""]) {
[keysArray addObject:@"postalCode"];
[valuesArray addObject:selectPostalCodeTextField.text];
}
if (keysArray.count) {
alternateArrayFoBusinessNamesArray = [dbManger fetchColumn:@"companyName" whereKeysAre:keysArray andValuesAre:valuesArray];
else
alternateArrayFoBusinessNamesArray = [dbManger fetchColumn:@"companyName"];
}
count = alternateArrayFoBusinessNamesArray.count;
break;
}
return count;
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel* pickerItemLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textFieldWidth, 40)];
[pickerItemLabel setFont:[UIFont fontWithName:appFontBold size:18]];
[pickerItemLabel setTextAlignment:NSTextAlignmentCenter];
switch (pickerView.tag) {
case 0:
{
NSString* name = [alternateArrayFoBusinessNamesArray objectAtIndex:row];
[pickerItemLabel setText:[alternateArrayFoBusinessNamesArray objectAtIndex:row]];
}
break;
case 1:
[pickerItemLabel setText:[citiesNamesArray objectAtIndex:row]];
break;
case 2:
if ([[businessTypesArray objectAtIndex:0]isKindOfClass:[NSDictionary class]])
[pickerItemLabel setText:[businessTypesArray objectAtIndex:row]];
else
[pickerItemLabel setText:[businessTypesArray objectAtIndex:row]];
break;
case 3:
[pickerItemLabel setText:[postalCodesArray objectAtIndex:row]];
break;
}
return pickerItemLabel;
}
答案 0 :(得分:0)
我发现问题是什么,除了pickerview的大小之外,每件事情都很好。我设置为0,就像在较旧的ios版本(< 9.0)中,pickerview高度被固定为0并且默认为216,现在它是可调整的,因此给出0意味着0而不是216.
" UIPickerView和UIDatePicker现在可以调整大小 自适应先前,即使这些视图也强制执行默认大小 你试图调整它们的大小。这些视图现在也默认为宽度 所有设备上的320点,而不是设备宽度 iPhone"
因此,我将其更改为某种尺寸,并且每件事情都正常工作