2015-11-30 67 views
0

我做了4個pickerviews,每個都有15個對象,我實現了所有的委託方法。返回1個組件數,行數也是正確的,但是在行方法行總是0,pickerview不是diplayed.help我在找到我錯在哪裏。 這裏是我的代碼uipickerview不顯示行數> 0的數據

-(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; 
} 
+1

你將不得不提供一些代碼,以便使社會幫助您,請提供選擇器視圖的實施。 –

+0

請添加您使用的代碼 –

+0

您的實施將會有所幫助。 –

回答

0

我想通了什麼問題,每一件事情,不同之處,pickerview的大小罰款。我設定0,作爲老年IOS版本(< 9.0)pickerview高度默認固定爲0和它到216,現在它是可調節的,使設定的0含義0不216.

iOS 9 Release Notes

「UIPickerView和UIDatePicker現在可調整大小,並且 自適應 - 以前,這些視圖會強制執行默認大小,即使 您試圖調整它們的大小也會忽略這些視圖。 iPhone上的設備寬度爲 「。

所以我它的變化在一定規模和每一件事情是工作的罰款