Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

christall109

macrumors 6502
Original poster
Jun 15, 2007
351
5
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. :)
 
Really? No one. Not even a place with a tutorial that I can find the answer? Or a suggestion for something to look over?
 
Really? No one. Not even a place with a tutorial that I can find the answer? Or a suggestion for something to look over?

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);
		}
	}
	
}
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.