Reputation: 11
how can i get 4 nsarrays into 1 pickerviewer each array has 4 names in them. so let say i have this:
Array1: Alex
Array2: Andrew
Array3: Sam
Array4: Rick
and now when i pull down the pickerviewer i want to see only the names alex, andrew, sam and rick in that pickerviewer.
and when i select a name (alex) i want to have 4 buttons that are changed in to the value of the numbers so when you tap the button you can call them.
can someone help me with this issue.
i am a bit brain frozen at this moment:S
Upvotes: 0
Views: 76
Reputation: 5681
Add them to a dictionary :
self.dict = [[NSMutableDictionary alloc] init]; //Obviously create a property first:
[dict setObject:array1 forKey:@"Alex"];
//etc .....
Then your picker delegates would look like:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [self.dict allKeys] count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.dict allKeys][row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *person = [dict allKeys][row];
NSArray *personDetails = [dict objectForKey:person];
}
Upvotes: 1
Reputation: 4249
Form what I can understand is you need to have an array with dictionaries
NSMutableArray *superArray = [NSMutableArray array]; //superArray should be declared in the interface
NSArray *setNames = [NSArray arrayWithObjects:@"Alex",@"Andrew",@"Sam",Rick,nil];
NSArray *alexArray = [NSArray arrayWithObjects:@"Tel nr:xxxxxxxxxx",@"Tel nr:xxxxxxxxxx",nil];
NSArray *andrewArray = [NSArray arrayWithObjects:@"Tel nr:xxxxxxxxxx",@"Tel nr:xxxxxxxxxx",nil];
NSArray *samArray = [NSArray arrayWithObjects:@"Tel nr:xxxxxxxxxx",@"Tel nr:xxxxxxxxxx",nil];
NSArray *rickArray = [NSArray arrayWithObjects:@"Tel nr:xxxxxxxxxx",@"Tel nr:xxxxxxxxxx",nil];
NSArray *totalArray = [NSArray arrayWithObjects:alexArray,andrewArray,samArray,rickArray,nil];
for (int i=0 ; i < [setNames count] ; i++){
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectAndKeys:[setNames objectAtIndex:i],@"setName",[totalArray objectAtIndex:i],@"telephoneArray" ,nil];
[superArray addObject:dictionary];
}
Now you have all data stored in the way you would need it
for pickerView delegates
set numberOfRowsInCOmponent to be [superArray count];
titleForRowInComponent to be [superArray objectAtIndex:row]valueForKey:@"setName"];
Further on selecting any particular name from pickerView
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// get the array of the selected setName
//Eg: After selecting Sam in pickerView
NSArray *selectedNamesTelephoneArray = [superArray objectAtIndex:row]valueForKey:@"telephoneArray"];
NSLog(@"the selected ones telephone numbers are %@",selectedNamesTelephoneArray);
}
Upvotes: 0
Reputation: 1033
are you sure you want to use UIPickerView ? If you aren't using more then 1 component then you can use UITableView. Each cell will contain only the name as you want (with method cellForRow:), and when you'll select it (didSelectRow:) it will show the former 4 buttons of that cell, which were hidden by now. when you type on another cell, the former one come back to its default state (the buttons are hidden), and of course if you tap one of the unhidden buttons you dial to the wanted number.
Making sense ?
Upvotes: 0