0

In my application i am using picker control,

I want to get the data from array to my picker view,

Array comes like this,

 PickerArray:(
    {
    CustEmail = [email protected];
    CustFirstName = ABC;
    CustID = 1;
    CustLastName = Test;
    CustPhoneNo = 12345;
    }

My picker has one component,

 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title;

title = [[PickerArray objectAtIndex:row]valueForKey:@"CustFirstName"];
NSLog(@"title:%@",title);

return title;

}

with this I am getting just one value If i want to get CustFirstName and Email in one row of picker component. Like ABC [email protected];

Please any one suggest how can i do that?

3 Answers 3

4

You can use stringWithFormat: to construct composite strings, like this:

title = [NSString stringWithFormat:@"%@ %@"
,   [[PickerArray objectAtIndex:row]valueForKey:@"CustFirstName"]
,   [[PickerArray objectAtIndex:row]valueForKey:@"CustEmail"]
];
Sign up to request clarification or add additional context in comments.

Comments

2

Compose string according to requirement:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{
  NSString *title = [NSString stringWithFormat:@"%@ %@",[[PickerArray objectAtIndex:row]valueForKey:@"CustFirstName"],[[PickerArray objectAtIndex:row]valueForKey:@"CustEmail"]];
 NSLog(@"title:%@",title);

 return title;
}

Comments

0

Try

title = [NSString stringWithFormat:@"%@ %@",[[PickerArray objectAtIndex:row]valueForKey:@"CustFirstName"],[[PickerArray objectAtIndex:row]valueForKey:@"CustEmail"]];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.