2 UIPickerViews in same UIView, 2nd Picker not displaying values...

Discussion in 'iOS Programming' started by christall109, Jan 30, 2010.

  1. christall109 macrumors 6502

    Joined:
    Jun 15, 2007
    #1
    I have 2 UIPickerViews on the same screen. I have the first one working and displaying and returning data. I added a second UIPicker and I have it returning values. However, my viewDidLoad function doesn't seem to be working properly.

    The first UIPicker loads and the string values are added and visible. However, my second UIPicker is not displaying my string values. But is returning values when I flick over the picker. The data is not being shown in the UI. It is blank.

    Here is the code from viewDid Load:

    Code:
    - (void)viewDidLoad {
    	[super viewDidLoad];
    	
    
    	meterPickerViewArray = [[NSMutableArray alloc] init];
    	for (int i = 0; i <= 9; i ++) {   // Set 'i' to every number from 1 to 9.
    		NSString *myString = [NSString stringWithFormat:@"%d", i];
    		[meterPickerViewArray addObject:myString]; //Add string to tableviewarray.
    	}
    		
    	timeSecondsPickerViewArray = [[NSMutableArray alloc] init]; //This seems to be the part not working correctly.
    	for (int ts = 0; ts <= 59; ts ++) {
    		NSString *mySecondString = [NSString stringWithFormat:@"%d", ts];
    		[timeSecondsPickerViewArray addObject:mySecondString];
    	}
    	
    }
    Any help or direction would be greatly appreciated. :)
     
  2. christall109 thread starter macrumors 6502

    Joined:
    Jun 15, 2007
    #2
    Really? No one. Not even a place with a tutorial that I can find the answer? Or a suggestion for something to look over?
     
  3. KVC, Feb 16, 2011
    Last edited by a moderator: Feb 16, 2011

    KVC macrumors newbie

    Joined:
    Feb 16, 2011
    #3
    Hi, I hope not is very later, you have implement of this way:

    Code:
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
    
    [INDENT][/INDENT]return 1;
    }
    
    - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
    	
    if (thePickerView == self.mypickerview1) {
    		return [array1 count];
    	}else{
                        if (thePickerView == self.mypickerview2) {
    		return [array2 count];
                        }
    	}
    }
    
    - (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    	
    	if (thePickerView == self.mypickerview1) {		
    		return [array1 objectAtIndex:row];
    	}else {
                          if (thePickerView == self.mypickerview2) {
    		return [array2 objectAtIndex:row];
                         }
    	}
    }
    
    - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    	if (thePickerView == self.mypickerview1) {
    		NSLog(@"Herarchy:  Selected Item: %@. Index of selected item: %i",[array1 objectAtIndex:row],row);
    	}else {
    		if (thePickerView == self.mypickerview2) {
    			NSLog(@"Domain:  Selected Item: %@. Index of selected item: %i",[array2 objectAtIndex:row],row);
    		}
    	}
    	
    }
     

Share This Page