0

在我的应用程序中,我使用选择器控件,

我想从数组中获取数据到我的选择器视图,

数组是这样来的,

 PickerArray:(
    {
    CustEmail = test@test.com;
    CustFirstName = ABC;
    CustID = 1;
    CustLastName = Test;
    CustPhoneNo = 12345;
    }

我的选择器有一个组件,

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

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

return title;

}

有了这个我只得到一个值如果我想在选择器组件的一行中获取 CustFirstName 和 Email。喜欢ABC test@test.com;

请任何人建议我该怎么做?

4

3 回答 3

4

您可以使用stringWithFormat:来构造复合字符串,如下所示:

title = [NSString stringWithFormat:@"%@ %@"
,   [[PickerArray objectAtIndex:row]valueForKey:@"CustFirstName"]
,   [[PickerArray objectAtIndex:row]valueForKey:@"CustEmail"]
];
于 2012-06-01T12:52:52.590 回答
2

根据要求编写字符串:

- (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;
}
于 2012-06-01T12:52:52.400 回答
0

尝试

title = [NSString stringWithFormat:@"%@ %@",[[PickerArray objectAtIndex:row]valueForKey:@"CustFirstName"],[[PickerArray objectAtIndex:row]valueForKey:@"CustEmail"]];
于 2012-06-01T12:56:01.263 回答